in editor/app/src/XcodeProjectPatcher.cs [374:459]
internal static void ReadAndApplyFirebaseConfig(
BuildTarget buildTarget, string pathToBuiltProject) {
// DLLs that trigger post processing by this method.
// We use the DLL names here as:
// * Pod dependencies may not be present if frameworks are manually
// being included.
// * DLLs may not be loaded in the Unity Editor App domain so we can't
// detect the module using reflection.
var invitesDll = "Firebase.Invites.dll";
var dllsThatRequireReversedClientId = new HashSet<string> {
"Firebase.Auth.dll",
"Firebase.DynamicLinks.dll",
invitesDll
};
bool reversedClientIdRequired = false;
bool invitesPresent = false;
// Search the asset database for the DLLs to handle projects where
// users move files around.
foreach (var assetGuid in AssetDatabase.FindAssets("t:Object")) {
var filename = Path.GetFileName(
AssetDatabase.GUIDToAssetPath(assetGuid));
if (dllsThatRequireReversedClientId.Contains(filename)) {
reversedClientIdRequired = true;
invitesPresent = filename == invitesDll;
}
}
if (!(invitesPresent || reversedClientIdRequired)) {
return;
}
ReadConfig();
// Read required data from the config file.
var configDict = GetConfig();
if (configDict.Count == 0) return;
string reversedClientId = null;
string bundleId = null;
if (!configDict.TryGetValue("REVERSED_CLIENT_ID",
out reversedClientId)) {
Measurement.analytics.Report("ios/xcodepatch/reversedclientid/failed",
"Add Reversed Client ID Failed");
Debug.LogError(
String.Format(DocRef.PropertyMissingForGoogleSignIn,
GOOGLE_SERVICES_INFO_PLIST_FILE, "REVERSED_CLIENT_ID",
Link.IOSAddApp));
}
if (!configDict.TryGetValue("BUNDLE_ID", out bundleId)) {
Debug.LogError(
String.Format(DocRef.PropertyMissingForGoogleSignIn,
GOOGLE_SERVICES_INFO_PLIST_FILE, "BUNDLE_ID", Link.IOSAddApp));
}
// Update the Xcode project's Info.plist.
string plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
var plist = new UnityEditor.iOS.Xcode.PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
var rootDict = plist.root;
UnityEditor.iOS.Xcode.PlistElementArray urlTypes = null;
if (rootDict.values.ContainsKey("CFBundleURLTypes")) {
urlTypes = rootDict["CFBundleURLTypes"].AsArray();
}
if (urlTypes == null) {
urlTypes = rootDict.CreateArray("CFBundleURLTypes");
}
if (reversedClientId != null) {
var googleType = urlTypes.AddDict();
googleType.SetString("CFBundleTypeRole", "Editor");
googleType.SetString("CFBundleURLName", "google");
googleType.CreateArray("CFBundleURLSchemes").AddString(
reversedClientId);
Measurement.analytics.Report("ios/xcodepatch/reversedclientid/success",
"Add Reversed Client ID Successful");
}
if (bundleId != null) {
var bundleType = urlTypes.AddDict();
bundleType.SetString("CFBundleTypeRole", "Editor");
bundleType.SetString("CFBundleURLName", bundleId);
bundleType.CreateArray("CFBundleURLSchemes").AddString(bundleId);
}
// Invites needs usage permission to access Contacts.
if (invitesPresent) {
if (!rootDict.values.ContainsKey("NSContactsUsageDescription")) {
rootDict.SetString("NSContactsUsageDescription", "Invite others to use the app.");
}
}
// Finished, Write to File
File.WriteAllText(plistPath, plist.WriteToString());
}