Update GoogleSignInIOSBuildPatch.cs

iOS
Hazim Bin Ijaz 2 months ago
parent 2e4278a0cc
commit 0962b33d64

@ -1,9 +1,11 @@
#if UNITY_IOS #if UNITY_IOS && UNITY_EDITOR
using System.IO;
using UnityEditor; using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor.Callbacks; using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode; using UnityEditor.iOS.Xcode;
using UnityEngine; using UnityEngine;
using System.IO;
public class GoogleSignInIOSBuildPatch public class GoogleSignInIOSBuildPatch
{ {
@ -19,10 +21,10 @@ public class GoogleSignInIOSBuildPatch
plist.ReadFromFile(plistPath); plist.ReadFromFile(plistPath);
PlistElementDict rootDict = plist.root; PlistElementDict rootDict = plist.root;
// 1. Add GIDClientID // 1. Set GIDClientID
rootDict.SetString("GIDClientID", GameConstants.iOS_ClientID); rootDict.SetString("GIDClientID", GameConstants.iOS_ClientID);
// 2. Add custom URL scheme // 2. Add CFBundleURLSchemes
PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes"); PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");
PlistElementDict urlDict = urlTypes.AddDict(); PlistElementDict urlDict = urlTypes.AddDict();
PlistElementArray schemes = urlDict.CreateArray("CFBundleURLSchemes"); PlistElementArray schemes = urlDict.CreateArray("CFBundleURLSchemes");
@ -35,7 +37,7 @@ public class GoogleSignInIOSBuildPatch
string appControllerPath = Path.Combine(pathToBuiltProject, "Classes", "UnityAppController.mm"); string appControllerPath = Path.Combine(pathToBuiltProject, "Classes", "UnityAppController.mm");
if (!File.Exists(appControllerPath)) if (!File.Exists(appControllerPath))
{ {
Debug.LogWarning("⚠️ UnityAppController.mm not found. Skipping patch."); Debug.LogWarning("⚠️ UnityAppController.mm not found.");
return; return;
} }
@ -48,14 +50,13 @@ public class GoogleSignInIOSBuildPatch
int index = content.IndexOf(marker); int index = content.IndexOf(marker);
if (index > -1) if (index > -1)
{ {
int insertAfter = content.IndexOf("{", index) + 1; int braceIndex = content.IndexOf("{", index);
content = content.Insert(insertAfter, "\n " + injection); if (braceIndex > -1)
{
content = content.Insert(braceIndex + 1, "\n " + injection);
File.WriteAllText(appControllerPath, content); File.WriteAllText(appControllerPath, content);
Debug.Log("✅ UnityAppController.mm patched with GIDClientID."); Debug.Log("✅ UnityAppController.mm patched with GIDClientID.");
} }
else
{
Debug.LogWarning("⚠️ didFinishLaunchingWithOptions not found in UnityAppController.mm");
} }
} }
} }

Loading…
Cancel
Save