From 1b6da6b04ba2beb49c3b23ab08a022f6026d5bac Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 07 十月 2026 18:24:49 +0800
Subject: [PATCH] 0312 欢游硬核新SDK - IOS打包;需要复测下 IOS包是否正常
---
Assets/Editor/XCodeProjectMod.cs | 433 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 360 insertions(+), 73 deletions(-)
diff --git a/Assets/Editor/XCodeProjectMod.cs b/Assets/Editor/XCodeProjectMod.cs
index 8f22f56..010c268 100644
--- a/Assets/Editor/XCodeProjectMod.cs
+++ b/Assets/Editor/XCodeProjectMod.cs
@@ -1,6 +1,7 @@
锘縰sing System;
using System.Collections.Generic;
using System.IO;
+using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.iOS.Xcode.Custom;
using UnityEngine;
@@ -10,6 +11,34 @@
// Channel 鎻掍欢瀛樻斁鐩綍锛圔uildIpa 鍓嶇敱 ClientPackage.BuildIpa 浠� _sdkPath 鎷疯礉鍒� Assets/Plugins/iOS/Channel锛�
private static readonly string iOSPluginPath = Application.dataPath + "/Plugins/iOS/Channel";
+ // ===== 娓犻亾鏍囪瘑锛氫笌 ClientPackage 涓� VersionConfig.appId / sdkFileName 瀵瑰簲 =====
+ private const string CHANNEL_SGHY = "sghy"; // 鍘熸湁娓犻亾锛坒impfunSDK + Firebase/Facebook/Adjust锛�
+ private const string CHANNEL_HYYH = "hyyh"; // 娆㈡父纭牳锛圚GameSDK锛�
+
+ private static string s_Channel = null;
+
+ /// <summary>褰撳墠鎵撳寘娓犻亾锛屾湭璇嗗埆鍒版椂鎸� sghy 澶勭悊锛屼繚璇佸師鏈夋墦鍖呰涓轰笉鍙�</summary>
+ private static string Channel
+ {
+ get
+ {
+ if (s_Channel == null)
+ {
+ s_Channel = DetectChannel();
+ }
+ return s_Channel;
+ }
+ }
+
+ private static bool IsSghy { get { return Channel == CHANNEL_SGHY; } }
+ private static bool IsHyyh { get { return Channel == CHANNEL_HYYH; } }
+
+ private static string DetectChannel()
+ {
+
+ return VersionConfig.Get().appId;;
+ }
+
[UnityEditor.Callbacks.PostProcessBuild(999)]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
@@ -18,18 +47,19 @@
return;
}
+ // 涓�娆� Editor 浼氳瘽鍙兘杩炵画鎵撳涓笭閬撶殑鍖咃紝杩欓噷閲嶆柊璇嗗埆娓犻亾
+ s_Channel = null;
+ Debug.Log("[XCodeProjectMod] 褰撳墠 iOS 娓犻亾: " + Channel);
DoPBXProject(path);
BuildPlist(path);
ModifyFile(path);
- // 鐢熸垚 .xcworkspace 缁撴瀯锛屾柟渚垮紑鍙戣�呭湪 Xcode 涓墜鍔� Add Package Dependency
- // SPM 渚濊禆蹇呴』閫氳繃 .xcworkspace 绠$悊锛�.xcodeproj 鍗曠嫭鏃犳硶姝g‘ resolve
- // 寮�鍙戣�呴渶鍦� Xcode 涓墜鍔� File 鈫� Add Package Dependency 娣诲姞浠ヤ笅浠撳簱锛屽苟閫夋嫨鎵�闇�鐨勪骇鍝佸寘锛�
- // - Firebase: https://github.com/firebase/firebase-ios-sdk
- // - Facebook: https://github.com/facebook/facebook-ios-sdk
- // - Adjust: https://github.com/adjust/ios_sdk
- CreateWorkspaceWithSPM(path);
+ // SPM 渚濊禆锛團irebase / Facebook / Adjust锛変负 sghy 娓犻亾浣跨敤锛岄渶瑕侀�氳繃 .xcworkspace 绠$悊
+ if (IsSghy)
+ {
+ CreateWorkspaceWithSPM(path);
+ }
}
static void DoPBXProject(string path)
@@ -47,53 +77,86 @@
project.SetBuildProperty(fwTargetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
-
- // Firebase 璋冭瘯鏃ュ織鍙傛暟
- project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsDebugEnabled");
- project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRDebugEnabled");
- project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsVerboseLoggingEnabled");
-
- // WebKit锛堟枃妗h姹傦級
- project.AddFrameworkToProject(fwTargetGUID, "WebKit.framework", true);
-
//UnityFramework
project.AddBuildProperty(fwTargetGUID, "OTHER_LDFLAGS", "-ObjC");
- // 娣诲姞 GoogleService-Info.plist 鍜� funshine.plist 鍒板伐绋�
- string[] configPlists = { "GoogleService-Info.plist", "funshine.plist" };
- foreach (var plistName in configPlists)
+ // sghy 娓犻亾锛欶irebase 璋冭瘯鏃ュ織鍙傛暟
+ if (IsSghy)
{
- string srcPath = iOSPluginPath + "/" + plistName;
- if (File.Exists(srcPath))
+ project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsDebugEnabled");
+ project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRDebugEnabled");
+ project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsVerboseLoggingEnabled");
+ // WebKit锛堟枃妗h姹傦級
+ project.AddFrameworkToProject(fwTargetGUID, "WebKit.framework", true);
+ // 娣诲姞 GoogleService-Info.plist 鍜� funshine.plist 鍒板伐绋�
+ string[] configPlists = { "GoogleService-Info.plist", "funshine.plist" };
+ foreach (var plistName in configPlists)
{
- string destPath = path + "/" + plistName;
- File.Copy(srcPath, destPath, true);
- string fileGuid = project.AddFile(plistName, plistName, PBXSourceTree.Source);
+ string srcPath = iOSPluginPath + "/" + plistName;
+ if (File.Exists(srcPath))
+ {
+ string destPath = path + "/" + plistName;
+ File.Copy(srcPath, destPath, true);
+ string fileGuid = project.AddFile(plistName, plistName, PBXSourceTree.Source);
+ project.AddFileToBuild(targetGUID, fileGuid);
+ }
+ else
+ {
+ Debug.LogWarning("[XCodeProjectMod] " + plistName + " 鏈壘鍒�: " + srcPath);
+ }
+ }
+ // hfsdk.xcframework 娣诲姞鍒板伐绋嬪苟璁剧疆涓� Embed & Sign锛坰ghy 娓犻亾锛�
+ string hfFrameworkPath = path + "/Frameworks/hfsdk.xcframework";
+ if (Directory.Exists(hfFrameworkPath))
+ {
+ string fileGuid = project.AddFile(hfFrameworkPath, "Frameworks/hfsdk.xcframework", PBXSourceTree.Source);
+ project.AddFileToBuild(fwTargetGUID, fileGuid);
+ // Embed & Sign: 娣诲姞鍒� main target 鐨� Embed Frameworks
project.AddFileToBuild(targetGUID, fileGuid);
}
- else
- {
- Debug.LogWarning("[XCodeProjectMod] " + plistName + " 鏈壘鍒�: " + srcPath);
- }
+
+ project.AddFrameworkToProject(fwTargetGUID, "AdServices.framework", true);
+ project.AddFrameworkToProject(fwTargetGUID, "AdSupport.framework", true);
+ project.AddFrameworkToProject(fwTargetGUID, "AppTrackingTransparency.framework", true);
+ project.AddFrameworkToProject(fwTargetGUID, "StoreKit.framework", true);
}
- // hfsdk.xcframework 娣诲姞鍒板伐绋嬪苟璁剧疆涓� Embed & Sign
- string hfFrameworkPath = path + "/Frameworks/hfsdk.xcframework";
- if (Directory.Exists(hfFrameworkPath))
+
+ // hyyh 娓犻亾锛欻GameSDK.xcframework / HGameChannelSdk.xcframework 璁剧疆涓� Embed & Sign
+ if (IsHyyh)
{
- string fileGuid = project.AddFile(hfFrameworkPath, "Frameworks/hfsdk.xcframework", PBXSourceTree.Source);
- project.AddFileToBuild(fwTargetGUID, fileGuid);
- // Embed & Sign: 娣诲姞鍒� main target 鐨� Embed Frameworks
- project.AddFileToBuild(targetGUID, fileGuid);
+ AddEmbedFramework(project, path, fwTargetGUID, targetGUID, "HGameSDK.xcframework");
+ AddEmbedFramework(project, path, fwTargetGUID, targetGUID, "HGameChannelSdk.xcframework");
}
-
- // Adjust SDK 渚濊禆鐨勭郴缁熸鏋讹紙鏂囨。瑕佹眰 Status 璁句负 Optional锛�
- project.AddFrameworkToProject(fwTargetGUID, "AdServices.framework", true);
- project.AddFrameworkToProject(fwTargetGUID, "AdSupport.framework", true);
- project.AddFrameworkToProject(fwTargetGUID, "AppTrackingTransparency.framework", true);
- project.AddFrameworkToProject(fwTargetGUID, "StoreKit.framework", true);
File.WriteAllText(_projectPath, project.WriteToString());
+ }
+
+ /// <summary>
+ /// 灏嗗鍑哄伐绋� Frameworks 鐩綍涓嬬殑 xcframework 鍔犲叆宸ョ▼骞惰缃� Embed & Sign銆�
+ /// Unity 浼氭妸 Assets/Plugins/iOS 涓嬬殑 .xcframework 鎷疯礉鍒� <瀵煎嚭宸ョ▼>/Frameworks 涓嬨��
+ /// </summary>
+ private static void AddEmbedFramework(PBXProject project, string projectPath, string fwTargetGUID, string targetGUID, string frameworkName)
+ {
+ string relPath = "Frameworks/" + frameworkName;
+ string frameworkPath = projectPath + "/" + relPath;
+ if (!Directory.Exists(frameworkPath))
+ {
+ // Unity 涓嶅悓鐗堟湰鏀剧疆浣嶇疆鍙兘涓嶅悓锛團rameworks 涓嬫垨鎻掍欢瀛愮洰褰曪級锛岃繖閲岄�掑綊鍏滃簳鏌ユ壘
+ string[] found = Directory.GetDirectories(projectPath, frameworkName, SearchOption.AllDirectories);
+ if (found == null || found.Length == 0)
+ {
+ Debug.LogWarning("[XCodeProjectMod] " + frameworkName + " 鏈壘鍒�: " + frameworkPath);
+ return;
+ }
+ frameworkPath = found[0];
+ relPath = frameworkPath.Substring(projectPath.Length).TrimStart('/', '\\').Replace("\\", "/");
+ }
+
+ string fileGuid = project.AddFile(frameworkPath, relPath, PBXSourceTree.Source);
+ project.AddFileToBuild(fwTargetGUID, fileGuid); // Link Binary With Libraries
+ project.AddFileToBuild(targetGUID, fileGuid); // Embed Frameworks
+ Debug.Log("[XCodeProjectMod] 宸叉坊鍔�(Embed & Sign): " + relPath);
}
/// <summary>
@@ -144,21 +207,40 @@
PlistElementDict _rootDict = _plist.root;
_rootDict.SetString("NSUserTrackingUsageDescription", "Please rest assured, granting permission will not access your private information on other websites. This permission is only used to identify the device and ensure service security and enhance browsing experience");
- // Facebook (funshine.plist: kFacebookAppID / kFacebookAppSecret)
- _rootDict.SetString("FacebookAppID", "1445747540428317");
- _rootDict.SetString("FacebookClientToken", "1103765897fb67ffc898e6a8ee2d9aec");
- _rootDict.SetString("FacebookDisplayName", "EZ PZ: Byte Heroes");
+ // sghy 娓犻亾锛欶acebook锛坒unshine.plist: kFacebookAppID / kFacebookAppSecret锛�
+ if (IsSghy)
+ {
+ _rootDict.SetString("FacebookAppID", "1445747540428317");
+ _rootDict.SetString("FacebookClientToken", "1103765897fb67ffc898e6a8ee2d9aec");
+ _rootDict.SetString("FacebookDisplayName", "EZ PZ: Byte Heroes");
- // 閫傞厤娆х洘鍦板尯鏀跨瓥娉曡 - Google Analytics 榛樿鍏佽
- _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE", true);
- _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE", true);
- _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA", true);
- _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS", true);
+ PlistElementArray nsURLTypes = _rootDict.CreateArray("CFBundleURLTypes");
+ var dict0 = nsURLTypes.AddDict();
+ dict0.SetString("CFBundleTypeRole", "Editor");
+ dict0.SetString("CFBundleURLName", "fb");
+ var schemesArray = dict0.CreateArray("CFBundleURLSchemes");
+ schemesArray.AddString("fb1445747540428317");
- // App 鍚嶇О鏈湴鍖�
- _rootDict.SetBoolean("Application has localized display name", true);
- _rootDict.SetString("CFBundleDevelopmentRegion", "english");
- _rootDict.SetString("Localization native development region", "english");
+ var array1 = _rootDict.CreateArray("LSApplicationQueriesSchemes");
+ array1.AddString("fbapi");
+ array1.AddString("fb-messenger-api");
+ array1.AddString("fbauth2");
+ array1.AddString("fbshareextension");
+ // 閫傞厤娆х洘鍦板尯鏀跨瓥娉曡 - Google Analytics 榛樿鍏佽
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_ANALYTICS_STORAGE", true);
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_STORAGE", true);
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_USER_DATA", true);
+ _rootDict.SetBoolean("GOOGLE_ANALYTICS_DEFAULT_ALLOW_AD_PERSONALIZATION_SIGNALS", true);
+ }
+
+
+ // App 鍚嶇О鏈湴鍖栵紙闇�瑕� InfoPlist.strings 涓瓨鍦� CFBundleDisplayName锛岃 CreateInfoPlistStrings锛�
+ if (HasDisplayName())
+ {
+ _rootDict.SetBoolean("Application has localized display name", true);
+ _rootDict.SetString("CFBundleDevelopmentRegion", "english");
+ _rootDict.SetString("Localization native development region", "english");
+ }
// ===== 鍚姩灞忕櫧搴曪紙Info.plist 鏂瑰紡锛歎ILaunchScreen -> Background color锛�=====
// iOS 13+ 鏀寔鐢� Info.plist 鐨� UILaunchScreen 瀛楀吀鎻忚堪鍚姩灞忥紝鏃犻渶 storyboard銆�
@@ -177,19 +259,6 @@
PlistElementDict launchScreenDict = _rootDict.CreateDict("UILaunchScreen");
launchScreenDict.SetString("UIColorName", launchScreenColorName);
// =====================================================================
-
- PlistElementArray nsURLTypes = _rootDict.CreateArray("CFBundleURLTypes");
- var dict0 = nsURLTypes.AddDict();
- dict0.SetString("CFBundleTypeRole", "Editor");
- dict0.SetString("CFBundleURLName", "fb");
- var schemesArray = dict0.CreateArray("CFBundleURLSchemes");
- schemesArray.AddString("fb1445747540428317");
-
- var array1 = _rootDict.CreateArray("LSApplicationQueriesSchemes");
- array1.AddString("fbapi");
- array1.AddString("fb-messenger-api");
- array1.AddString("fbauth2");
- array1.AddString("fbshareextension");
File.WriteAllText(_plistPath, _plist.WriteToString());
}
@@ -247,6 +316,27 @@
private static void ModifyFile(string projectPath)
{
+ if (IsHyyh)
+ {
+ ModifyFileForHyyh(projectPath);
+ }
+ else
+ {
+ ModifyFileForSghy(projectPath);
+ }
+
+ // 鍒涘缓 InfoPlist.strings锛圓pp 鍚嶇О鏈湴鍖栵級
+ CreateInfoPlistStrings(projectPath);
+
+ // Sign In with Apple entitlements
+ SetupEntitlements(projectPath);
+ }
+
+ /// <summary>
+ /// sghy 娓犻亾锛坒impfunSDK + Firebase/Facebook/Adjust锛夌殑 AppController 娉ㄥ叆
+ /// </summary>
+ private static void ModifyFileForSghy(string projectPath)
+ {
//淇敼UnityAppController.mm 鏂囦欢
var _xclass = new XClass(projectPath + "/Classes/UnityAppController.mm");
//寮曞叆fimpfunSDK
@@ -289,9 +379,179 @@
{
Debug.LogWarning("[XCodeProjectMod] UnityViewControllerBase.mm 鏂囦欢涓嶅瓨鍦紝璺宠繃 viewDidAppear 娉ㄥ叆銆傛 Unity 鐗堟湰鍙兘宸茬Щ闄よ鏂囦欢銆�");
}
+ }
- // 鍒涘缓 InfoPlist.strings锛圓pp 鍚嶇О鏈湴鍖栵級
- CreateInfoPlistStrings(projectPath);
+ /// <summary>
+ /// hyyh 娓犻亾锛圚GameSDK锛夌殑 AppController 娉ㄥ叆锛�
+ /// 寮曞叆 UniversalSDK銆佹毚闇� IOSUniyMessageHandle 缁� C#锛圓otSdkUtility锛夈�佸垵濮嬪寲骞惰浆鍙� AppDelegate 鐢熷懡鍛ㄦ湡銆�
+ /// </summary>
+ private static void ModifyFileForHyyh(string projectPath)
+ {
+ string mmPath = projectPath + "/Classes/UnityAppController.mm";
+ string hPath = projectPath + "/Classes/UnityAppController.h";
+
+ if (!File.Exists(mmPath) || !File.Exists(hPath))
+ {
+ Debug.LogError("[XCodeProjectMod][hyyh] UnityAppController 鏂囦欢涓嶅瓨鍦�: " + projectPath + "/Classes");
+ return;
+ }
+
+ // 寮曞叆 UniversalSDK锛堟笭閬撴彃浠� wgyx/UniversalSDK.h锛�
+ InsertBelowPattern(mmPath, @"#include\s+""PluginBase/AppDelegateListener\.h""",
+ "#import \"UniversalSDK.h\"", "import UniversalSDK");
+
+ // C# 璋冪敤鍏ュ彛锛屼笌 AotSdkUtility.IOSUniyMessageHandle 瀵瑰簲
+ string entryCode = "\n" +
+ "extern \"C\" void IOSUniyMessageHandle(const char* jsonString) {\n" +
+ " [GetAppController().universalSDK HandleUnityMessage:[NSString stringWithUTF8String:jsonString]];\n" +
+ "}";
+ InsertBelowPattern(mmPath, @"extern\s+""C""\s+ScreenOrientation\s+UnityCurrentOrientation\s*\(\s*\)",
+ entryCode, "IOSUniyMessageHandle");
+
+ // 鍒濆鍖� HGameSDK锛堝繀椤诲湪涓荤嚎绋嬨�佸湪 delegate 璁剧疆涔嬪悗锛�
+ string initCode = "\n" +
+ " _universalSDK = [[UniversalSDK alloc] init];\n" +
+ " [_universalSDK HGameSDKInit:application didFinishLaunchingWithOptions:launchOptions];";
+ InsertBelowPattern(mmPath, @"::printf\(""-> applicationDidFinishLaunching\(\\n""\);",
+ initCode, "initSdk");
+
+ // ===== UIApplicationDelegate 鐢熷懡鍛ㄦ湡杞彂锛圚GameSDK 蹇呮帴锛�=====
+ InsertBelowPattern(mmPath, @"- \(BOOL\)application:[^\n]*openURL:[^\n]*\n\s*\{",
+ " [_universalSDK application:[UIApplication sharedApplication] openURL:url options:options];", "openURL");
+
+ InsertBelowPattern(mmPath, @"- \(void\)applicationWillResignActive:[^\n]*\n\s*\{",
+ " [_universalSDK applicationWillResignActive:[UIApplication sharedApplication]];", "willResignActive");
+
+ InsertBelowPattern(mmPath, @"- \(void\)applicationDidEnterBackground:[^\n]*\n\s*\{",
+ " [_universalSDK applicationDidEnterBackground:[UIApplication sharedApplication]];", "didEnterBackground");
+
+ InsertBelowPattern(mmPath, @"- \(void\)applicationWillEnterForeground:[^\n]*\n\s*\{",
+ " [_universalSDK applicationWillEnterForeground:[UIApplication sharedApplication]];", "willEnterForeground");
+
+ InsertBelowPattern(mmPath, @"- \(void\)applicationDidBecomeActive:[^\n]*\n\s*\{",
+ " [_universalSDK applicationDidBecomeActive:[UIApplication sharedApplication]];", "didBecomeActive");
+
+ InsertBelowPattern(mmPath, @"- \(void\)applicationWillTerminate:[^\n]*\n\s*\{",
+ " [_universalSDK applicationWillTerminate:[UIApplication sharedApplication]];", "willTerminate");
+
+ InsertBelowPattern(mmPath, @"- \(void\)application:[^\n]*didRegisterForRemoteNotificationsWithDeviceToken:[^\n]*\n\s*\{",
+ " [_universalSDK application:[UIApplication sharedApplication] didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];", "didRegisterToken");
+
+ InsertBelowPattern(mmPath, @"- \(void\)application:[^\n]*didFailToRegisterForRemoteNotificationsWithError:[^\n]*\n\s*\{",
+ " [_universalSDK application:[UIApplication sharedApplication] didFailToRegisterForRemoteNotificationsWithError:error];", "didFailRegister");
+
+ // 闈欓粯杩滅▼閫氱煡锛氫紭鍏堝鐢� Unity 宸叉湁鐨勭幇浠e洖璋冿紱Unity 鏈0鏄庤鏂规硶鏃惰ˉ涓�涓畬鏁村疄鐜帮紙鏂囨。蹇呮帴锛�
+ string remotePattern = @"- \(void\)application:[^\n]*didReceiveRemoteNotification:[^\n]*fetchCompletionHandler:[^\n]*\n\s*\{";
+ string remoteForward = " [_universalSDK application:[UIApplication sharedApplication] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];";
+ if (!InsertBelowPattern(mmPath, remotePattern, remoteForward, "didReceiveRemoteNotification"))
+ {
+ AppendMethod(mmPath,
+ "- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler\n{\n" +
+ " [_universalSDK application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];\n}",
+ "didReceiveRemoteNotification");
+ }
+
+ // 灞忓箷鏂瑰悜锛氭笭閬撹繑鍥� 0 琛ㄧず涓嶆帴绠★紝缁х画璧� Unity 鍘熸湁閫昏緫
+ InsertBelowPattern(mmPath, @"- \(NSUInteger\)application:[^\n]*supportedInterfaceOrientationsForWindow:[^\n]*\n\s*\{",
+ " NSUInteger sdkOrientations = [_universalSDK application:[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:window];\n" +
+ " if (sdkOrientations != 0) {\n return sdkOrientations;\n }", "supportedInterfaceOrientations");
+
+ // Universal Link锛氫紭鍏堝鐢� Unity 宸叉湁鍥炶皟锛涙病鏈夊垯琛ヤ竴涓畬鏁村疄鐜帮紙鏂囨。蹇呮帴锛�
+ string continuePattern = @"- \(BOOL\)application:[^\n]*continueUserActivity:[^\n]*\n\s*\{";
+ string continueForward = " if ([_universalSDK application:[UIApplication sharedApplication] continueUserActivity:userActivity restorationHandler:restorationHandler]) {\n return YES;\n }";
+ if (!InsertBelowPattern(mmPath, continuePattern, continueForward, "continueUserActivity"))
+ {
+ AppendMethod(mmPath,
+ "- (BOOL)application:(UIApplication*)application continueUserActivity:(NSUserActivity*)userActivity restorationHandler:(void (^)(NSArray*))restorationHandler\n{\n" +
+ " if ([_universalSDK application:application continueUserActivity:userActivity restorationHandler:restorationHandler]) {\n return YES;\n }\n" +
+ " return NO;\n}",
+ "continueUserActivity");
+ }
+
+ // 淇敼 UnityAppController.h
+ var _xclass = new XClass(hPath);
+ _xclass.WriteBelow("@class DisplayConnection;", "@class UniversalSDK;");
+ _xclass.WriteBelow("DisplayConnection* _mainDisplay;", "UniversalSDK* _universalSDK;");
+ _xclass.WriteBelow("@property (readonly, copy, nonatomic) DisplayConnection* mainDisplay;",
+ "@property (readonly, copy, nonatomic) UniversalSDK* universalSDK;");
+ }
+
+ /// <summary>
+ /// 鎸夋鍒欐煡鎵炬敞鍏ョ偣锛屽苟鍦ㄨ琛屼箣鍚庢彃鍏ヤ唬鐮併�傛壘涓嶅埌鏃跺彧鍛婅锛屼笉淇敼鏂囦欢銆�
+ /// </summary>
+ private static bool InsertBelowPattern(string filePath, string pattern, string text, string tag)
+ {
+ if (!File.Exists(filePath))
+ {
+ Debug.LogWarning("[XCodeProjectMod] 鏂囦欢涓嶅瓨鍦紝璺宠繃娉ㄥ叆[" + tag + "]: " + filePath);
+ return false;
+ }
+
+ string content = File.ReadAllText(filePath);
+ Match match = Regex.Match(content, pattern);
+ if (!match.Success)
+ {
+ Debug.LogWarning("[XCodeProjectMod] 鏈壘鍒版敞鍏ョ偣[" + tag + "]锛岃烦杩�: " + pattern);
+ return false;
+ }
+
+ int lineEnd = content.IndexOf('\n', match.Index + match.Length - 1);
+ if (lineEnd < 0)
+ {
+ lineEnd = content.Length;
+ }
+
+ content = content.Substring(0, lineEnd) + "\n" + text + content.Substring(lineEnd);
+ File.WriteAllText(filePath, content);
+ return true;
+ }
+
+ /// <summary>
+ /// 鍦� UnityAppController.mm 鐨� @implementation UnityAppController 鍧楁湯灏捐拷鍔犱竴涓畬鏁寸殑 delegate 鏂规硶銆�
+ /// 鐢ㄤ簬 Unity 鏈0鏄庤鏂规硶銆佷絾娓犻亾 SDK 瑕佹眰蹇呴』杞彂鐨勫満鏅紙鏂囨。蹇呮帴椤癸級銆�
+ /// </summary>
+ private static bool AppendMethod(string filePath, string methodText, string tag)
+ {
+ if (!File.Exists(filePath))
+ {
+ Debug.LogWarning("[XCodeProjectMod] 鏂囦欢涓嶅瓨鍦紝璺宠繃杩藉姞[" + tag + "]: " + filePath);
+ return false;
+ }
+
+ string content = File.ReadAllText(filePath);
+ int implIndex = content.IndexOf("@implementation UnityAppController", StringComparison.Ordinal);
+ if (implIndex < 0)
+ {
+ Debug.LogError("[XCodeProjectMod] 鏈壘鍒� @implementation UnityAppController锛屾棤娉曡拷鍔燵" + tag + "]");
+ return false;
+ }
+
+ int endIndex = content.IndexOf("@end", implIndex, StringComparison.Ordinal);
+ if (endIndex < 0)
+ {
+ Debug.LogError("[XCodeProjectMod] 鏈壘鍒� @end锛屾棤娉曡拷鍔燵" + tag + "]");
+ return false;
+ }
+
+ content = content.Substring(0, endIndex) + "\n" + methodText + "\n\n" + content.Substring(endIndex);
+ File.WriteAllText(filePath, content);
+ Debug.Log("[XCodeProjectMod] 宸茶拷鍔� delegate 鏂规硶[" + tag + "]");
+ return true;
+ }
+
+ /// <summary>
+ /// 鍚勬笭閬撶殑 App 鏄剧ず鍚嶇О锛歔娓犻亾] = { 鑻辨枃, 绠�浣撲腑鏂� }
+ /// 鏈厤缃殑娓犻亾涓嶄細鐢熸垚鏈湴鍖栧悕绉帮紝鐩存帴浣跨敤 PlayerSettings 涓殑 Product Name銆�
+ /// </summary>
+ private static readonly Dictionary<string, string[]> DisplayNames = new Dictionary<string, string[]>
+ {
+ { CHANNEL_SGHY, new[] { "EZ PZ", "鎳掍汉涓夊浗" } },
+ // TODO hyyh 娓犻亾纭 App 鍚嶇О鍚庡湪杩欓噷琛ュ厖锛歿 CHANNEL_HYYH, new[] { "鑻辨枃鍚�", "涓枃鍚�" } },
+ };
+
+ private static bool HasDisplayName()
+ {
+ return DisplayNames.ContainsKey(Channel);
}
/// <summary>
@@ -299,6 +559,14 @@
/// </summary>
private static void CreateInfoPlistStrings(string projectPath)
{
+ if (!HasDisplayName())
+ {
+ Debug.LogWarning("[XCodeProjectMod] 娓犻亾 " + Channel + " 鏈厤缃� App 鏄剧ず鍚嶇О锛岃烦杩� InfoPlist.strings 鏈湴鍖�");
+ return;
+ }
+
+ string[] names = DisplayNames[Channel];
+
// 鑻辨枃锛堥粯璁わ級
string enDir = projectPath + "/English.lproj";
if (!Directory.Exists(enDir))
@@ -308,7 +576,7 @@
string enStringsPath = enDir + "/InfoPlist.strings";
if (!File.Exists(enStringsPath))
{
- File.WriteAllText(enStringsPath, "CFBundleDisplayName = \"EZ PZ\";\n");
+ File.WriteAllText(enStringsPath, "CFBundleDisplayName = \"" + names[0] + "\";\n");
}
// 涓枃
@@ -320,7 +588,7 @@
string zhStringsPath = zhDir + "/InfoPlist.strings";
if (!File.Exists(zhStringsPath))
{
- File.WriteAllText(zhStringsPath, "CFBundleDisplayName = \"鎳掍汉涓夊浗\";\n");
+ File.WriteAllText(zhStringsPath, "CFBundleDisplayName = \"" + names[1] + "\";\n");
}
// 灏� InfoPlist.strings 娣诲姞鍒� Xcode 宸ョ▼
@@ -341,14 +609,33 @@
string zhFileGuid = project.AddFile(zhRelPath, zhRelPath, PBXSourceTree.Source);
project.AddFileToBuild(targetGUID, zhFileGuid);
- // 娣诲姞 Sign In with Apple entitlements
+ File.WriteAllText(_projectPath, project.WriteToString());
+ }
+ catch (System.Exception e)
+ {
+ Debug.LogError("[XCodeProjectMod] 灏� InfoPlist.strings 娣诲姞鍒� Xcode 宸ョ▼澶辫触: " + e.Message);
+ }
+ }
+
+ /// <summary>
+ /// Sign In with Apple entitlements锛堜笌娓犻亾鏃犲叧锛屾墍鏈夋笭閬撻兘闇�瑕侊級
+ /// </summary>
+ private static void SetupEntitlements(string projectPath)
+ {
+ string _projectPath = PBXProject.GetPBXProjectPath(projectPath);
+ try
+ {
+ PBXProject project = new PBXProject();
+ project.ReadFromString(File.ReadAllText(_projectPath));
+ string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName());
+
AddEntitlements(projectPath, project, targetGUID);
File.WriteAllText(_projectPath, project.WriteToString());
}
catch (System.Exception e)
{
- Debug.LogError("[XCodeProjectMod] 灏� InfoPlist.strings 娣诲姞鍒� Xcode 宸ョ▼澶辫触: " + e.Message);
+ Debug.LogError("[XCodeProjectMod] 娣诲姞 entitlements 澶辫触: " + e.Message);
}
}
--
Gitblit v1.8.0