From 0962b33d6405199ca77e6435e122c5190ea17651 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Fri, 9 May 2025 18:05:16 +0500 Subject: [PATCH] Update GoogleSignInIOSBuildPatch.cs --- Assets/Scripts/GoogleSignInIOSBuildPatch.cs | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/GoogleSignInIOSBuildPatch.cs b/Assets/Scripts/GoogleSignInIOSBuildPatch.cs index 34446859..610c8572 100644 --- a/Assets/Scripts/GoogleSignInIOSBuildPatch.cs +++ b/Assets/Scripts/GoogleSignInIOSBuildPatch.cs @@ -1,9 +1,11 @@ -#if UNITY_IOS -using System.IO; +#if UNITY_IOS && UNITY_EDITOR using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; using UnityEngine; +using System.IO; public class GoogleSignInIOSBuildPatch { @@ -19,10 +21,10 @@ public class GoogleSignInIOSBuildPatch plist.ReadFromFile(plistPath); PlistElementDict rootDict = plist.root; - // 1. Add GIDClientID + // 1. Set GIDClientID rootDict.SetString("GIDClientID", GameConstants.iOS_ClientID); - // 2. Add custom URL scheme + // 2. Add CFBundleURLSchemes PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); PlistElementDict urlDict = urlTypes.AddDict(); PlistElementArray schemes = urlDict.CreateArray("CFBundleURLSchemes"); @@ -35,7 +37,7 @@ public class GoogleSignInIOSBuildPatch string appControllerPath = Path.Combine(pathToBuiltProject, "Classes", "UnityAppController.mm"); if (!File.Exists(appControllerPath)) { - Debug.LogWarning("⚠️ UnityAppController.mm not found. Skipping patch."); + Debug.LogWarning("⚠️ UnityAppController.mm not found."); return; } @@ -48,14 +50,13 @@ public class GoogleSignInIOSBuildPatch int index = content.IndexOf(marker); if (index > -1) { - int insertAfter = content.IndexOf("{", index) + 1; - content = content.Insert(insertAfter, "\n " + injection); - File.WriteAllText(appControllerPath, content); - Debug.Log("✅ UnityAppController.mm patched with GIDClientID."); - } - else - { - Debug.LogWarning("⚠️ didFinishLaunchingWithOptions not found in UnityAppController.mm"); + int braceIndex = content.IndexOf("{", index); + if (braceIndex > -1) + { + content = content.Insert(braceIndex + 1, "\n " + injection); + File.WriteAllText(appControllerPath, content); + Debug.Log("✅ UnityAppController.mm patched with GIDClientID."); + } } } }