#if UNITY_IOS using System.IO; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; namespace RocketPush.Editor { public static class PanPushBuildInjector { private const string _defaultTargetName = "Unity-iPhone"; [PostProcessBuild] public static void Inject(BuildTarget buildTarget, string path) { var projPath = PBXProject.GetPBXProjectPath(path); var xcodeProject = new PBXProject(); xcodeProject.ReadFromFile(projPath); #if UNITY_2019_3_OR_NEWER var targetGuid = xcodeProject.GetUnityMainTargetGuid(); #else var targetGuid = xcodeProject.TargetGuidByName(_defaultTargetName); #endif xcodeProject.AddFrameworkToProject(targetGuid, "UserNotifications.framework", false); string plistPath = string.Format("{0}{1}Info.plist", path, Path.DirectorySeparatorChar); PlistDocument plist = new PlistDocument(); plist.ReadFromString(File.ReadAllText(plistPath)); // Get root PlistElementDict rootDict = plist.root; rootDict.SetBoolean("FirebaseMessagingAutoInitEnabled", false); // Write to file File.WriteAllText(plistPath, plist.WriteToString()); var manager = new ProjectCapabilityManager(projPath, GetEntitlementsPath(path, xcodeProject, targetGuid, _defaultTargetName), null, xcodeProject.GetUnityMainTargetGuid()); manager.AddPushNotifications(false); manager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications | BackgroundModesOptions.BackgroundFetch); manager.WriteToFile(); xcodeProject.WriteToFile(projPath); } // Returns exisiting file if found, otherwises provides a default name to use private static string GetEntitlementsPath(string path, PBXProject project, string targetGUID, string targetName) { // Check if there is already an eltitlements file configured in the Xcode project #if UNITY_2018_2_OR_NEWER var relativeEntitlementPath = project.GetBuildPropertyForConfig(targetGUID, "CODE_SIGN_ENTITLEMENTS"); if (relativeEntitlementPath != null) { var entitlementPath = path + Path.DirectorySeparatorChar + relativeEntitlementPath; if (File.Exists(entitlementPath)) { return entitlementPath; } } #endif // No existing file, use a new name return path + Path.DirectorySeparatorChar + targetName + Path.DirectorySeparatorChar + targetName + ".entitlements"; } } } #endif