Added a preprocessor script
parent
945aac36af
commit
2e4278a0cc
@ -0,0 +1,63 @@
|
||||
#if UNITY_IOS
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
using UnityEngine;
|
||||
|
||||
public class GoogleSignInIOSBuildPatch
|
||||
{
|
||||
[PostProcessBuild(100)]
|
||||
public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToBuiltProject)
|
||||
{
|
||||
if (buildTarget != BuildTarget.iOS) return;
|
||||
|
||||
string plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
|
||||
|
||||
// === Modify Info.plist ===
|
||||
PlistDocument plist = new PlistDocument();
|
||||
plist.ReadFromFile(plistPath);
|
||||
PlistElementDict rootDict = plist.root;
|
||||
|
||||
// 1. Add GIDClientID
|
||||
rootDict.SetString("GIDClientID", GameConstants.iOS_ClientID);
|
||||
|
||||
// 2. Add custom URL scheme
|
||||
PlistElementArray urlTypes = rootDict.CreateArray("CFBundleURLTypes");
|
||||
PlistElementDict urlDict = urlTypes.AddDict();
|
||||
PlistElementArray schemes = urlDict.CreateArray("CFBundleURLSchemes");
|
||||
schemes.AddString(GameConstants.iOS_URL_Scheme);
|
||||
|
||||
plist.WriteToFile(plistPath);
|
||||
Debug.Log("✅ Info.plist patched with GIDClientID and CFBundleURLSchemes.");
|
||||
|
||||
// === Modify UnityAppController.mm ===
|
||||
string appControllerPath = Path.Combine(pathToBuiltProject, "Classes", "UnityAppController.mm");
|
||||
if (!File.Exists(appControllerPath))
|
||||
{
|
||||
Debug.LogWarning("⚠️ UnityAppController.mm not found. Skipping patch.");
|
||||
return;
|
||||
}
|
||||
|
||||
string content = File.ReadAllText(appControllerPath);
|
||||
string injection = $"[GIDSignIn sharedInstance].clientID = @\"{GameConstants.iOS_ClientID}\";";
|
||||
|
||||
if (!content.Contains(injection))
|
||||
{
|
||||
string marker = "didFinishLaunchingWithOptions:(NSDictionary*)launchOptions";
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 74a4088da3768004389d6516bc9a559a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue