From b2ceae0fd6d520fd068de9ddc5d1e9c11da3983d Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期一, 15 六月 2026 23:39:51 +0800
Subject: [PATCH] 0312 同步文档

---
 Assets/Editor/XCodeProjectMod.cs |  285 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 261 insertions(+), 24 deletions(-)

diff --git a/Assets/Editor/XCodeProjectMod.cs b/Assets/Editor/XCodeProjectMod.cs
index 331e453..22b6a9b 100644
--- a/Assets/Editor/XCodeProjectMod.cs
+++ b/Assets/Editor/XCodeProjectMod.cs
@@ -46,8 +46,16 @@
         project.SetBuildProperty(targetGUID, "ENABLE_BITCODE", "NO");
         project.SetBuildProperty(targetGUID, "DEVELOPMENT_TEAM", TEAM);
 
+        // 1.1 鐜瑕佹眰锛歩OS 13.0 鍙婁互涓�
+        project.SetBuildProperty(targetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
+        project.SetBuildProperty(fwTargetGUID, "IPHONEOS_DEPLOYMENT_TARGET", "13.0");
+
         project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
-        project.AddBuildProperty(targetGUID, "GCC_GENERATE_DEBUGGING_SYMBOLS", "NO");
+
+        // Firebase 璋冭瘯鏃ュ織鍙傛暟
+        project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsDebugEnabled");
+        project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRDebugEnabled");
+        project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-FIRAnalyticsVerboseLoggingEnabled");
 
         //wkwebview
         project.AddFrameworkToProject(fwTargetGUID, "WebKit.framework", true);
@@ -92,7 +100,162 @@
             }
         }
 
+        // 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());
+
+        // SPM 渚濊禆锛欶irebase / Facebook / Adjust锛圲nity PBXProject API 涓嶆敮鎸� SPM锛岄渶鐩存帴鎿嶄綔 pbxproj锛�
+        AddSwiftPackageDependencies(_projectPath, targetGUID);
+    }
+
+    /// <summary>
+    /// 鍚� pbxproj 娉ㄥ叆 Swift Package Manager 渚濊禆锛圶CRemoteSwiftPackageReference + XCSwiftPackageProductDependency锛�
+    /// 鐗堟湰鍙烽渶鏍规嵁 demo 鎴栧疄闄呴渶姹傝皟鏁�
+    /// </summary>
+    private static void AddSwiftPackageDependencies(string projectPath, string targetGUID)
+    {
+        string content = File.ReadAllText(projectPath);
+
+        // ---- 1. 鐢熸垚 GUID锛堜娇鐢ㄧ‘瀹氭�у懡鍚嶉伩鍏嶉噸澶嶆敞鍏ワ級----
+        string firebasePkgRefGuid  = "FIMPSPM00001"; // XCRemoteSwiftPackageReference
+        string fbPkgRefGuid        = "FIMPSPM00002";
+        string adjustPkgRefGuid    = "FIMPSPM00003";
+
+        string firebaseAnalyticsProdGuid = "FIMPSPM00011"; // XCSwiftPackageProductDependency (FirebaseAnalytics)
+        string firebaseCoreProdGuid      = "FIMPSPM00012"; // XCSwiftPackageProductDependency (FirebaseCore)
+        string fbCoreKitProdGuid         = "FIMPSPM00021"; // XCSwiftPackageProductDependency (FacebookCore)
+        string fbLoginKitProdGuid        = "FIMPSPM00022"; // XCSwiftPackageProductDependency (FacebookLogin)
+        string adjustProdGuid            = "FIMPSPM00031"; // XCSwiftPackageProductDependency (Adjust)
+
+        // 濡傛灉宸茬粡娉ㄥ叆杩囷紝璺宠繃
+        if (content.Contains(firebasePkgRefGuid))
+        {
+            UnityEngine.Debug.Log("[XCodeProjectMod] SPM dependencies already injected, skipping.");
+            return;
+        }
+
+        // ---- 2. XCRemoteSwiftPackageReference section ----
+        string pkgRefSection = "/* XCRemoteSwiftPackageReference section */";
+        string pkgRefEntries = string.Format(
+            "\t\t{{0}} /* XCRemoteSwiftPackageReference \"Firebase\" */ = {{isa = XCRemoteSwiftPackageReference; repositoryURL = \"https://github.com/firebase/firebase-ios-sdk\"; requirement = {{kind = upToNextMajorVersion; minimumVersion = 10.24.0; }}; }};\n" +
+            "\t\t{{1}} /* XCRemoteSwiftPackageReference \"Facebook\" */ = {{isa = XCRemoteSwiftPackageReference; repositoryURL = \"https://github.com/facebook/facebook-ios-sdk\"; requirement = {{kind = upToNextMajorVersion; minimumVersion = 17.0.0; }}; }};\n" +
+            "\t\t{{2}} /* XCRemoteSwiftPackageReference \"Adjust\" */ = {{isa = XCRemoteSwiftPackageReference; repositoryURL = \"https://github.com/adjust/ios_sdk\"; requirement = {{kind = upToNextMajorVersion; minimumVersion = 4.38.2; }}; }};\n",
+            firebasePkgRefGuid, fbPkgRefGuid, adjustPkgRefGuid);
+        content = content.Replace(pkgRefSection, pkgRefSection + "\n" + pkgRefEntries);
+
+        // ---- 3. XCSwiftPackageProductDependency section ----
+        string pkgProdSection = "/* XCSwiftPackageProductDependency section */";
+        string pkgProdEntries = string.Format(
+            "\t\t{{0}} /* FirebaseAnalytics */ = {{isa = XCSwiftPackageProductDependency; package = {{1}} /* XCRemoteSwiftPackageReference \"Firebase\" */; productName = FirebaseAnalytics; }};\n" +
+            "\t\t{{2}} /* FirebaseCore */ = {{isa = XCSwiftPackageProductDependency; package = {{1}} /* XCRemoteSwiftPackageReference \"Firebase\" */; productName = FirebaseCore; }};\n" +
+            "\t\t{{3}} /* FacebookCore */ = {{isa = XCSwiftPackageProductDependency; package = {{4}} /* XCRemoteSwiftPackageReference \"Facebook\" */; productName = FacebookCore; }};\n" +
+            "\t\t{{5}} /* FacebookLogin */ = {{isa = XCSwiftPackageProductDependency; package = {{4}} /* XCRemoteSwiftPackageReference \"Facebook\" */; productName = FacebookLogin; }};\n" +
+            "\t\t{{6}} /* Adjust */ = {{isa = XCSwiftPackageProductDependency; package = {{7}} /* XCRemoteSwiftPackageReference \"Adjust\" */; productName = Adjust; }};\n",
+            firebaseAnalyticsProdGuid, firebasePkgRefGuid,
+            firebaseCoreProdGuid,
+            fbCoreKitProdGuid, fbPkgRefGuid,
+            fbLoginKitProdGuid,
+            adjustProdGuid, adjustPkgRefGuid);
+        content = content.Replace(pkgProdSection, pkgProdSection + "\n" + pkgProdEntries);
+
+        // ---- 4. PBXNativeTarget packageProductDependencies ----
+        // 鍦� target 鐨� packageProductDependencies 涓坊鍔犲紩鐢�
+        string pkgProdDeps = string.Format(
+            "\t\t\t\tpackageProductDependencies = (\n" +
+            "\t\t\t\t\t{0} /* FirebaseAnalytics */,\n" +
+            "\t\t\t\t\t{1} /* FirebaseCore */,\n" +
+            "\t\t\t\t\t{2} /* FacebookCore */,\n" +
+            "\t\t\t\t\t{3} /* FacebookLogin */,\n" +
+            "\t\t\t\t\t{4} /* Adjust */,\n" +
+            "\t\t\t\t);",
+            firebaseAnalyticsProdGuid, firebaseCoreProdGuid,
+            fbCoreKitProdGuid, fbLoginKitProdGuid,
+            adjustProdGuid);
+
+        // 鎵惧埌 main target 鐨� buildPhases 缁撴潫浣嶇疆闄勮繎锛屾彃鍏� packageProductDependencies
+        // 鍦� target 鐨� buildPhases 鏁扮粍缁撴潫鍚庢坊鍔�
+        string targetMarker = targetGUID + " /* " + PBXProject.GetUnityTargetName() + " */";
+        int targetStart = content.IndexOf(targetMarker);
+        if (targetStart >= 0)
+        {
+            // 鎵惧埌杩欎釜 target dict 涓殑 buildPhases 缁撴潫鐨� );
+            int buildPhasesEnd = FindClosingParen(content, targetStart, "buildPhases");
+            if (buildPhasesEnd >= 0)
+            {
+                content = content.Insert(buildPhasesEnd, "\n" + pkgProdDeps);
+            }
+        }
+
+        // ---- 5. PBXProject packageReferences ----
+        // 鍦� project 鐨� packageReferences 涓坊鍔犲紩鐢�
+        string pkgRefs = string.Format(
+            "\t\t\t\tpackageReferences = (\n" +
+            "\t\t\t\t\t{{0}} /* XCRemoteSwiftPackageReference \"Firebase\" */,\n" +
+            "\t\t\t\t\t{{1}} /* XCRemoteSwiftPackageReference \"Facebook\" */,\n" +
+            "\t\t\t\t\t{{2}} /* XCRemoteSwiftPackageReference \"Adjust\" */,\n" +
+            "\t\t\t\t);",
+            firebasePkgRefGuid, fbPkgRefGuid, adjustPkgRefGuid);
+
+        // 鍦� PBXProject 鐨� mainGroup 鍚庨潰娣诲姞 packageReferences
+        int projectSection = content.IndexOf("/* PBXProject */ = {");
+        if (projectSection >= 0)
+        {
+            // 鎵惧埌 attributes 鍖哄潡
+            int attrsPos = content.IndexOf("attributes = {", projectSection);
+            if (attrsPos >= 0)
+            {
+                // 鍦� attributes 闂嫭鍙峰墠鎻掑叆
+                int attrsClose = content.IndexOf("};", attrsPos + 14);
+                if (attrsClose >= 0)
+                {
+                    content = content.Insert(attrsClose, "\n" + pkgRefs);
+                }
+            }
+        }
+
+        // ---- 6. PBXFrameworksBuildPhase ----
+        // 灏� SPM product 鍔犲埌 Frameworks build phase
+        string frameworkBuildPhaseMarker = "/* Frameworks */ = {";
+        int fwPhaseIdx = content.IndexOf(frameworkBuildPhaseMarker);
+        if (fwPhaseIdx >= 0)
+        {
+            int filesStart = content.IndexOf("files = (", fwPhaseIdx);
+            if (filesStart >= 0)
+            {
+                int filesEnd = content.IndexOf(");", filesStart + 9);
+                if (filesEnd >= 0)
+                {
+                    string fwEntries = string.Format(
+                        "\t\t\t\t{0} /* FirebaseAnalytics in Frameworks */,\n" +
+                        "\t\t\t\t{1} /* FirebaseCore in Frameworks */,\n" +
+                        "\t\t\t\t{2} /* FacebookCore in Frameworks */,\n" +
+                        "\t\t\t\t{3} /* FacebookLogin in Frameworks */,\n" +
+                        "\t\t\t\t{4} /* Adjust in Frameworks */,\n",
+                        firebaseAnalyticsProdGuid, firebaseCoreProdGuid,
+                        fbCoreKitProdGuid, fbLoginKitProdGuid,
+                        adjustProdGuid);
+                    content = content.Insert(filesEnd, fwEntries);
+                }
+            }
+        }
+
+        File.WriteAllText(projectPath, content);
+        UnityEngine.Debug.Log("[XCodeProjectMod] SPM dependencies (Firebase/Facebook/Adjust) injected successfully.");
+    }
+
+    /// <summary>
+    /// 鍦� pbxproj 鏂囨湰涓紝浠庢寚瀹� key锛堝 buildPhases锛夌殑鏁扮粍璧峰浣嶇疆鎵惧埌鍏堕棴鎷彿 ");" 鐨勪綅缃�
+    /// </summary>
+    private static int FindClosingParen(string content, int searchStart, string key)
+    {
+        int keyIdx = content.IndexOf(key + " = (", searchStart);
+        if (keyIdx < 0) return -1;
+        int openIdx = content.IndexOf("(", keyIdx);
+        return content.IndexOf(");", openIdx);
     }
 
     private static void BuildPlist(string path)
@@ -103,23 +266,22 @@
         _plist.ReadFromString(File.ReadAllText(_plistPath));
 
         PlistElementDict _rootDict = _plist.root;
-        PlistElementDict _nsAppTransportSecurity = _rootDict.CreateDict("NSAppTransportSecurity");
-        _nsAppTransportSecurity.SetBoolean("NSAllowsArbitraryLoads", true);
-
-        _rootDict.SetString("NSPhotoLibraryAddUsageDescription", "You must grant the photo album permission to take screenshots and save data for users");
-        _rootDict.SetString("NSCameraUsageDescription", "Please allow application permission access, otherwise the function cannot be started");
-        _rootDict.SetString("NSUserTrackingUsageDescription", "This guide will display personalized ads specifically for you");
-
-        // Adjust (funshine.plist: kAdjustAppToken)
-        _rootDict.SetString("AdjustAppToken", "nbevz727gy68");
+        _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", "");
         _rootDict.SetString("FacebookDisplayName", "Legend of the Sword Master");
 
-        _rootDict.SetBoolean("FacebookAutoLogAppEventsEnabled", true);
-        _rootDict.SetBoolean("FacebookAdvertiserIDCollectionEnabled", true);
+        // 閫傞厤娆х洘鍦板尯鏀跨瓥娉曡 - 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 鍚嶇О鏈湴鍖�
+        _rootDict.SetBoolean("Application has localized display name", true);
+        _rootDict.SetString("CFBundleDevelopmentRegion", "english");
 
         PlistElementArray nsURLTypes = _rootDict.CreateArray("CFBundleURLTypes");
         var dict0 = nsURLTypes.AddDict();
@@ -130,18 +292,7 @@
 
         var array1 = _rootDict.CreateArray("LSApplicationQueriesSchemes");
         array1.AddString("fbapi");
-        array1.AddString("fbapi20130214");
-        array1.AddString("fbapi20130410");
-        array1.AddString("fbapi20130702");
-        array1.AddString("fbapi20131010");
-        array1.AddString("fbapi20131219");
-        array1.AddString("fbapi20140410");
-        array1.AddString("fbapi20140116");
-        array1.AddString("fbapi20150313");
-        array1.AddString("fbapi20150629");
-        array1.AddString("fbapi20160328");
-        array1.AddString("fbauth");
-        array1.AddString("fb-messenger-share-api");
+        array1.AddString("fb-messenger-api");
         array1.AddString("fbauth2");
         array1.AddString("fbshareextension");
 
@@ -170,6 +321,7 @@
 
         // fimpfunSDK 鐢熷懡鍛ㄦ湡
         _xclass.WriteBelow("- (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options\n{", "\n    [_fimpfunBridge application:app openURL:url options:options];");
+        _xclass.WriteBelow("- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation\n{", "\n    return [_fimpfunBridge application:application openURL:url sourceApplication:sourceApplication annotation:annotation];");
         _xclass.WriteBelow("::printf(\"-> applicationDidBecomeActive()\\n\");", "[_fimpfunBridge applicationDidBecomeActive:application];");
 
 
@@ -179,6 +331,91 @@
         _xclass.WriteBelow("DisplayConnection*  _mainDisplay;", "FimpfunBridge* _fimpfunBridge;");
         _xclass.WriteBelow("@property (readonly, copy, nonatomic) DisplayConnection*    mainDisplay;",
                            "@property (readonly, copy, nonatomic) FimpfunBridge*  fimpfunBridge;");
+
+        // 3.1 閫傞厤娆х洘鏀跨瓥锛氬湪 viewDidAppear 涓皟鐢� adaptingEUGDPR锛堟枃妗h姹傦級
+        var _viewController = new XClass(projectPath + "/Classes/UnityViewControllerBase.mm");
+        _viewController.WriteBelow("@implementation UnityViewControllerBase",
+            "\n- (void)viewDidAppear:(BOOL)animated {\n    [super viewDidAppear:animated];\n    [GetAppController().fimpfunBridge viewDidAppear];\n}\n");
+
+        // 鍒涘缓 InfoPlist.strings锛圓pp 鍚嶇О鏈湴鍖栵級
+        CreateInfoPlistStrings(projectPath);
+    }
+
+    /// <summary>
+    /// 鍒涘缓 InfoPlist.strings 鏂囦欢鐢ㄤ簬 App 鍚嶇О鏈湴鍖�
+    /// </summary>
+    private static void CreateInfoPlistStrings(string projectPath)
+    {
+        string stringsDir = projectPath + "/English.lproj";
+        if (!Directory.Exists(stringsDir))
+        {
+            Directory.CreateDirectory(stringsDir);
+        }
+        string stringsPath = stringsDir + "/InfoPlist.strings";
+        if (!File.Exists(stringsPath))
+        {
+            File.WriteAllText(stringsPath, "CFBundleDisplayName = \"Legend of the Sword Master\";\n");
+        }
+
+        // 灏� InfoPlist.strings 娣诲姞鍒� Xcode 宸ョ▼
+        string _projectPath = PBXProject.GetPBXProjectPath(projectPath);
+        PBXProject project = new PBXProject();
+        project.ReadFromString(File.ReadAllText(_projectPath));
+        string targetGUID = project.TargetGuidByName(PBXProject.GetUnityTargetName());
+
+        string relPath = "English.lproj/InfoPlist.strings";
+        string fileGuid = project.AddFile(relPath, relPath, PBXSourceTree.Source);
+        project.AddFileToBuild(targetGUID, fileGuid);
+
+        // 娣诲姞 Sign In with Apple entitlements
+        AddEntitlements(projectPath, project, targetGUID);
+
+        File.WriteAllText(_projectPath, project.WriteToString());
+    }
+
+    /// <summary>
+    /// 娣诲姞 Sign In with Apple 绛� entitlements
+    /// </summary>
+    private static void AddEntitlements(string projectPath, PBXProject project, string targetGUID)
+    {
+        string entPath = projectPath + "/" + PBXProject.GetUnityTargetName() + ".entitlements";
+
+        // 濡傛灉 entitlements 鏂囦欢涓嶅瓨鍦紝鍒涘缓
+        if (!File.Exists(entPath))
+        {
+            string entContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+                "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" +
+                "<plist version=\"1.0\">\n" +
+                "<dict>\n" +
+                "\t<key>com.apple.developer.applesignin</key>\n" +
+                "\t<array>\n" +
+                "\t\t<string>Default</string>\n" +
+                "\t</array>\n" +
+                "</dict>\n" +
+                "</plist>\n";
+            File.WriteAllText(entPath, entContent);
+        }
+        else
+        {
+            // 宸叉湁 entitlements 鏂囦欢锛屾鏌ユ槸鍚﹀凡鏈� Sign In with Apple
+            string existingContent = File.ReadAllText(entPath);
+            if (!existingContent.Contains("com.apple.developer.applesignin"))
+            {
+                existingContent = existingContent.Replace("</dict>",
+                    "\t<key>com.apple.developer.applesignin</key>\n" +
+                    "\t<array>\n" +
+                    "\t\t<string>Default</string>\n" +
+                    "\t</array>\n" +
+                    "</dict>");
+                File.WriteAllText(entPath, existingContent);
+            }
+        }
+
+        // 灏� entitlements 鏂囦欢鍔犲叆宸ョ▼骞惰缃� build property
+        string entFileName = PBXProject.GetUnityTargetName() + ".entitlements";
+        string fileGuid = project.AddFile(entFileName, entFileName, PBXSourceTree.Source);
+        project.AddFileToBuild(targetGUID, fileGuid);
+        project.SetBuildProperty(targetGUID, "CODE_SIGN_ENTITLEMENTS", entFileName);
     }
 
     

--
Gitblit v1.8.0