Exemple #1
0
        public void OnPostprocessBuild(BuildReport report)
        {
#if UNITY_IOS
            BuildTarget buildTarget = report.summary.platform;
            string      path        = report.summary.outputPath;

            if (buildTarget != BuildTarget.iOS)
            {
                return;
            }

            string projPath = PBXProject.GetPBXProjectPath(path);

            // buid settings
            PBXProject proj = new PBXProject();
            proj.ReadFromFile(projPath);
            var targetGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
            proj.SetBuildProperty(targetGuid, "VALIDATE_WORKSPACE", "True");
            proj.SetBuildProperty(targetGuid, "SWIFT_VERSION", "5.0");

            // capabilities
            ProjectCapabilityManager manager = new ProjectCapabilityManager(
                projPath,
                "Entitlements.entitlements",
                PBXProject.GetUnityTargetName()
                );

            manager.AddSignInWithApple();
            manager.AddPushNotifications(false);

            // save setup
            manager.WriteToFile();
            proj.WriteToFile(projPath);
#endif
        }
Exemple #2
0
    private static void addCapability(string pathToBuiltProject, string projPath, PBXProject proj, string target)
    {
        var dummy            = CreateInstance <XcodeBuildScript>();
        var entitlementsFile = dummy.entitlementsFile;

        DestroyImmediate(dummy);

        // Copy the entitlement file to the xcode project
        var entitlementPath     = AssetDatabase.GetAssetPath(entitlementsFile);
        var entitlementFileName = Path.GetFileName(entitlementPath);
        var unityTarget         = PBXProject.GetUnityTargetName();
        var relativeDestination = unityTarget + "/" + entitlementFileName;
        var desPath             = pathToBuiltProject + "/" + relativeDestination;

        if (File.Exists(desPath))
        {
            File.Delete(desPath);
        }
        FileUtil.CopyFileOrDirectory(entitlementPath, desPath);
        // Add the pbx configs to include the entitlements files on the project
        proj.AddFile(relativeDestination, entitlementFileName);
        proj.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", relativeDestination);

        // Add Capability
        var capManager = new ProjectCapabilityManager(projPath, entitlementFileName, unityTarget);

        capManager.AddPushNotifications(true);
        capManager.AddInAppPurchase();
        capManager.WriteToFile();
    }
Exemple #3
0
    private static void PatchPBXProject(string path, bool needLocationFramework, bool addPushNotificationCapability, bool useReleaseAPSEnv)
    {
        var pbxProjectPath = PBXProject.GetPBXProjectPath(path);

        var needsToWriteChanges = false;

        var pbxProject = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(pbxProjectPath));

        string mainTarget;
        string unityFrameworkTarget;

        var unityMainTargetGuidMethod      = pbxProject.GetType().GetMethod("GetUnityMainTargetGuid");
        var unityFrameworkTargetGuidMethod = pbxProject.GetType().GetMethod("GetUnityFrameworkTargetGuid");

        if (unityMainTargetGuidMethod != null && unityFrameworkTargetGuidMethod != null)
        {
            mainTarget           = (string)unityMainTargetGuidMethod.Invoke(pbxProject, null);
            unityFrameworkTarget = (string)unityFrameworkTargetGuidMethod.Invoke(pbxProject, null);
        }
        else
        {
            mainTarget           = pbxProject.TargetGuidByName("Unity-iPhone");
            unityFrameworkTarget = mainTarget;
        }

        // Add necessary frameworks.
        if (!pbxProject.ContainsFramework(unityFrameworkTarget, "UserNotifications.framework"))
        {
            pbxProject.AddFrameworkToProject(unityFrameworkTarget, "UserNotifications.framework", true);
            needsToWriteChanges = true;
        }
        if (needLocationFramework && !pbxProject.ContainsFramework(unityFrameworkTarget, "CoreLocation.framework"))
        {
            pbxProject.AddFrameworkToProject(unityFrameworkTarget, "CoreLocation.framework", false);
            needsToWriteChanges = true;
        }

        if (needsToWriteChanges)
        {
            File.WriteAllText(pbxProjectPath, pbxProject.WriteToString());
        }

        // Update the entitlements file.
        if (addPushNotificationCapability)
        {
            var entitlementsFileName = pbxProject.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS");
            if (entitlementsFileName == null)
            {
                var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
                entitlementsFileName = string.Format("{0}.entitlements", bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1));
            }

            var capManager = new ProjectCapabilityManager(pbxProjectPath, entitlementsFileName, "Unity-iPhone");
            capManager.AddPushNotifications(!useReleaseAPSEnv);
            capManager.WriteToFile();
        }
    }
Exemple #4
0
        protected override void Process(BuildTarget target, string buildPath)
        {
            ProjectCapabilityManager capabilities =
                new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(buildPath), buildPath + "/" + entitlementsPath, PBXProject.GetUnityTargetName());

            capabilities.AddPushNotifications(development);
            capabilities.WriteToFile();
        }
        private static void AddCapability(string projPath)
        {
            string targetName = PBXProject.GetUnityTargetName();
            var    postfix    = ReleaseConfig.iOS.GetValue(ReleaseConfig.iOS.KeyDefine.BundlePostfix);
            ProjectCapabilityManager capManager = new ProjectCapabilityManager(projPath, postfix + ".entitlements", targetName);

            capManager.AddBackgroundModes(BackgroundModesOptions.BackgroundFetch | BackgroundModesOptions.RemoteNotifications);
            capManager.AddPushNotifications(true);

            capManager.AddInAppPurchase();

            capManager.WriteToFile();
        }
        public void AddPushNotificationsWorks()
        {
            SetupTestProject();
            ResetGuidGenerator();

            var capManager = new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(GetTestOutputPath()), "test.entitlements", PBXProject.GetUnityTargetName());

            capManager.AddPushNotifications(true);
            capManager.WriteToFile();

            TestOutputProject(capManager.project, "add_pushnotification.pbxproj");
            TestOutput("test.entitlements", "add_pushnotification.entitlements");
        }
Exemple #7
0
        /// <summary>
        /// Add the required capabilities and entitlements for OneSignal
        /// </summary>
        private void AddProjectCapabilities()
        {
            var targetGuid = _project.GetMainTargetGuid();
            var targetName = _project.GetMainTargetName();

            var entitlementsPath = GetEntitlementsPath(targetGuid, targetName);
            var projCapability   = new ProjectCapabilityManager(_projectPath, entitlementsPath, targetName);

            projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
            projCapability.AddPushNotifications(false);
            projCapability.AddAppGroups(new[] { _appGroupName });

            projCapability.WriteToFile();
        }
Exemple #8
0
    private static void OnPostProcessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget == BuildTarget.iOS)
        {
            _path = path;

            AddFramework();

            AddInfoPlist();

            var projCapability = new ProjectCapabilityManager(_projPath, "Unity-iPhone/mmk.entitlements", "Unity-iPhone");

            projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
            projCapability.AddPushNotifications(Debug.isDebugBuild);
            projCapability.WriteToFile();
        }
    }
        static void AddCapabilities(PBXProject proj, string targetGuid, ProjectCapabilityManager capManager)
        {
            if (ISD_Settings.Instance.Capabilities.Count == 0)
            {
                return;
            }



            foreach (var cap in ISD_Settings.Instance.Capabilities)
            {
                switch (cap.CapabilityType)
                {
                case ISD_CapabilityType.Cloud:
                    var cloudSettings = ISD_Settings.Instance.iCloudCapabilitySettings;
                    capManager.AddiCloud(cloudSettings.KeyValueStorage, cloudSettings.iCloudDocument, new string[] { });
                    break;

                case ISD_CapabilityType.InAppPurchase:
                    capManager.AddInAppPurchase();
                    break;

                case ISD_CapabilityType.GameCenter:
                    capManager.AddGameCenter();
                    break;

                case ISD_CapabilityType.PushNotifications:
                    var pushSettings = ISD_Settings.Instance.PushNotificationsCapabilitySettings;
                    capManager.AddPushNotifications(pushSettings.Development);
                    break;

                default:
                    var    capability           = ISD_PBXCapabilityTypeUtility.ToPBXCapability(cap.CapabilityType);
                    string entitlementsFilePath = null;
                    if (!string.IsNullOrEmpty(cap.EntitlementsFilePath))
                    {
                        entitlementsFilePath = cap.EntitlementsFilePath;
                    }


                    proj.AddCapability(targetGuid, capability, entitlementsFilePath, cap.AddOptionalFramework);
                    break;
                }
            }
        }
Exemple #10
0
        private static void SetCapabilitiesSimple(string buildPath, string entitlementsName)
        {
            string     pbxPath    = PBXProject.GetPBXProjectPath(buildPath);
            PBXProject pbxProject = new PBXProject();

            pbxProject.ReadFromFile(pbxPath);
            var target_name = PBXProject.GetUnityTargetName();
            // var target_guid = pbxProject.TargetGuidByName(target_name);

            var capManager = new ProjectCapabilityManager(pbxPath, entitlementsName, target_name);

            capManager.AddGameCenter();
            capManager.AddInAppPurchase();
            bool developmentMode = true; // Development mode should be used while testing your application outside of the App Store.

            capManager.AddPushNotifications(developmentMode);
            capManager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications); //todo: Problem is: is not setting up remote notification flag

            capManager.WriteToFile();                                                  // will update Info List, Will update Capability Entitlements
        }
Exemple #11
0
        public static void OnPostprocessBuildHandler(BuildTarget buildTarget, string path)
        {
            var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            var proj = new PBXProject();

            proj.ReadFromString(File.ReadAllText(projPath));

            var target = proj.GetUnityMainTargetGuid();

            proj.AddFrameworkToProject(target, "UserNotifications.framework", true);

            proj.AddCapability(target, PBXCapabilityType.PushNotifications);

            if (Directory.Exists(ICONS_PROJECT_PATH))
            {
                foreach (var file in Directory.GetFiles(ICONS_PROJECT_PATH, "*.png",
                                                        SearchOption.AllDirectories))
                {
                    var dstLocalPath        = Path.GetFileName(file);
                    var resourcesBuildPhase = proj.GetResourcesBuildPhaseByTarget(target);
                    var fileRef             = proj.AddFile(dstLocalPath, dstLocalPath);

                    File.Copy(file, Path.Combine(path, dstLocalPath), true);
                    proj.AddFileToBuild(target, fileRef);
                }
            }

            File.WriteAllText(projPath, proj.WriteToString());

            var capabilities =
                new ProjectCapabilityManager(PBXProject.GetPBXProjectPath(path), "app.entitlements", "Unity-iPhone");

            capabilities.AddPushNotifications(true);
            capabilities.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
            capabilities.WriteToFile();
        }
Exemple #12
0
    private static void AddCapabilities(PBXProject project, string pathToBuildProject)
    {
        string targetGuid = project.GetUnityMainTargetGuid();
        string relativeEntitlementsFilePath = ProductName + "." + "entitlements";

        ProjectCapabilityManager manager = new ProjectCapabilityManager(pathToBuildProject + "/Unity-iPhone.xcodeproj/project.pbxproj", relativeEntitlementsFilePath, "Unity-iPhone");

        // 1. game center
        manager.AddGameCenter();
        if (project.ContainsFramework(targetGuid, "GameKit.framework") == false)
        {
            Debug.Log("Add GameKit.framework");
            project.AddFrameworkToProject(targetGuid, "GameKit.framework", true);
        }

        // 2. purchase
        manager.AddInAppPurchase();
        if (project.ContainsFramework(targetGuid, "StoreKit.framework") == false)
        {
            Debug.Log("Add StoreKit.framework");
            project.AddFrameworkToProject(targetGuid, "StoreKit.framework", true);
        }

        // 3. remote push
        manager.AddPushNotifications(true);
        project.AddFile(relativeEntitlementsFilePath, relativeEntitlementsFilePath);
        project.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeEntitlementsFilePath);

        // 4. background
        manager.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);

        // 4. domains
        //string[] domains = { "xxx"};
        //manager.AddAssociatedDomains(domains);

        manager.WriteToFile();
    }
Exemple #13
0
    static void ProcessPBXProject(string pathToBuiltProject)
    {
        var unityProjPath = Application.dataPath.Replace("Assets", "");

        string     projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj     = new PBXProject();

        proj.ReadFromString(File.ReadAllText(projPath));
        string target = proj.TargetGuidByName("Unity-iPhone");

        var settings = GetiOSBuildOptions();

        //1.1 framework && lib
        if (settings.SystemFiles != null)
        {
            foreach (var fileName in settings.SystemFiles)
            {
                if (fileName.EndsWith(".framework"))
                {
                    proj.AddFrameworkToProject(target, fileName, false);
                }
                else
                {
                    var fileGuid = proj.AddFile("usr/lib/" + fileName, "Frameworks/" + fileName, PBXSourceTree.Sdk);
                    proj.AddFileToBuild(target, fileGuid);
                }
            }
        }

        //2 Capabilities
        if (settings.Capability != null)
        {
            foreach (var name in settings.Capability)
            {
                switch (name)
                {
                case "GameCenter":
                    proj.AddCapability(target, PBXCapabilityType.GameCenter);
                    break;

                case "InAppPurchase":
                    proj.AddCapability(target, PBXCapabilityType.InAppPurchase);
                    break;

                case "PushNotifications":
                    proj.AddCapability(target, PBXCapabilityType.PushNotifications);
                    var bundleIdLastIndex = settings.BundleIdentifier.LastIndexOf('.') + 1;
                    var entitlementName   = string.Format("{0}.entitlements", settings.BundleIdentifier.Substring(bundleIdLastIndex));
                    var capManager        = new ProjectCapabilityManager(projPath, entitlementName, PBXProject.GetUnityTargetName());
                    capManager.AddPushNotifications(true);
                    capManager.WriteToFile();
                    File.Copy(Path.Combine(pathToBuiltProject, entitlementName), Path.Combine(pathToBuiltProject, "Unity-iPhone", entitlementName), true);
                    break;

                default: break;
                }
            }
        }

        //3 Info(Info.plist)
        string plistPath = pathToBuiltProject + "/Info.plist";
        var    plist     = new PlistDocument();

        plist.ReadFromString(File.ReadAllText(plistPath));
        var plistRoot = plist.root;

        //麦克风权限
        plistRoot.SetString("NSMicrophoneUsageDescription", "用于游戏内语音功能时访问麦克风收录语音");
        plist.WriteToFile(plistPath);

        //4 Build Settings
        // 关闭bitcode(tolua不支持)
        proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

        //5 class
        string unityAppControllerPath = pathToBuiltProject + "/Classes/UnityAppController.mm";

        // 6 appiconset
        if (!string.IsNullOrEmpty(settings.AppIconSetPath))
        {
            string dstPath = pathToBuiltProject + "/Unity-iPhone/Images.xcassets/AppIcon.appiconset/";
            string srcPath = Path.Combine(unityProjPath, settings.AppIconSetPath);
            foreach (var file in Directory.GetFiles(srcPath))
            {
                var to = Path.Combine(dstPath, Path.GetFileName(file));
                File.Copy(file, to, true);
            }
        }

        // Save PBXProject
        proj.WriteToFile(projPath);
    }
        static void AddCapabilities(PBXProject proj, string targetGuid, ProjectCapabilityManager capManager)
        {
            var capability = ISD_Settings.Instance.Capability;

            if (capability.iCloud.Enabled)
            {
                if (capability.iCloud.iCloudDocument || capability.iCloud.customContainers.Count > 0)
                {
                    capManager.AddiCloud(capability.iCloud.keyValueStorage, capability.iCloud.iCloudDocument, capability.iCloud.customContainers.ToArray());
                }
                else
                {
                    capManager.AddiCloud(capability.iCloud.keyValueStorage, false, null);
                }
            }

            if (capability.PushNotifications.Enabled)
            {
                capManager.AddPushNotifications(capability.PushNotifications.development);
            }

            if (capability.GameCenter.Enabled)
            {
                capManager.AddGameCenter();
            }

            if (capability.Wallet.Enabled)
            {
                capManager.AddWallet(capability.Wallet.passSubset.ToArray());
            }

            if (capability.Siri.Enabled)
            {
                capManager.AddSiri();
            }

            if (capability.ApplePay.Enabled)
            {
                capManager.AddApplePay(capability.ApplePay.merchants.ToArray());
            }

            if (capability.InAppPurchase.Enabled)
            {
                capManager.AddInAppPurchase();
            }

            if (capability.Maps.Enabled)
            {
                var options = MapsOptions.None;
                foreach (var opt in capability.Maps.options)
                {
                    MapsOptions opt2 = (MapsOptions)opt;
                    options |= opt2;
                }
                capManager.AddMaps(options);
            }

            if (capability.PersonalVPN.Enabled)
            {
                capManager.AddPersonalVPN();
            }

            if (capability.BackgroundModes.Enabled)
            {
                var options = BackgroundModesOptions.None;
                foreach (var opt in capability.BackgroundModes.options)
                {
                    BackgroundModesOptions opt2 = (BackgroundModesOptions)opt;
                    options |= opt2;
                }
                capManager.AddBackgroundModes(options);
            }


            if (capability.InterAppAudio.Enabled)
            {
                capManager.AddInterAppAudio();
            }

            if (capability.KeychainSharing.Enabled)
            {
                capManager.AddKeychainSharing(capability.KeychainSharing.accessGroups.ToArray());
            }

            if (capability.AssociatedDomains.Enabled)
            {
                capManager.AddAssociatedDomains(capability.AssociatedDomains.domains.ToArray());
            }

            if (capability.AppGroups.Enabled)
            {
                capManager.AddAppGroups(capability.AppGroups.groups.ToArray());
            }

            if (capability.DataProtection.Enabled)
            {
                capManager.AddDataProtection();
            }

            if (capability.HomeKit.Enabled)
            {
                capManager.AddHomeKit();
            }

            if (capability.HealthKit.Enabled)
            {
                capManager.AddHealthKit();
            }

            if (capability.WirelessAccessoryConfiguration.Enabled)
            {
                capManager.AddWirelessAccessoryConfiguration();
            }

            /*
             *
             *
             * if (ISD_Settings.Instance.Capabilities.Count == 0) {
             *  return;
             * }
             *
             *
             * foreach (var cap in ISD_Settings.Instance.Capabilities) {
             *  switch(cap.CapabilityType) {
             *
             *
             *       case ISD_CapabilityType.InAppPurchase:
             *          capManager.AddInAppPurchase();
             *          break;
             *      case ISD_CapabilityType.GameCenter:
             *          capManager.AddGameCenter();
             *          break;
             *      case ISD_CapabilityType.PushNotifications:
             *          var pushSettings = ISD_Settings.Instance.PushNotificationsCapabilitySettings;
             *          capManager.AddPushNotifications(pushSettings.Development);
             *          break;
             *
             *      default:
             *          var capability = ISD_PBXCapabilityTypeUtility.ToPBXCapability(cap.CapabilityType);
             *          string entitlementsFilePath = null;
             *          if(!string.IsNullOrEmpty(cap.EntitlementsFilePath)) {
             *              entitlementsFilePath = cap.EntitlementsFilePath;
             *          }
             *
             *
             *          proj.AddCapability(targetGuid, capability, entitlementsFilePath, cap.AddOptionalFramework);
             *          break;
             *  }
             * }
             */
        }
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
                #if PLATFORM_IOS
        if (buildTarget == BuildTarget.iOS)
        {
            var projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";

            var proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));


            string mainTarget;
            string unityFrameworkTarget;

            var unityMainTargetGuidMethod      = proj.GetType().GetMethod("GetUnityMainTargetGuid");
            var unityFrameworkTargetGuidMethod = proj.GetType().GetMethod("GetUnityFrameworkTargetGuid");


            if (unityMainTargetGuidMethod != null && unityFrameworkTargetGuidMethod != null)
            {
                mainTarget           = (string)unityMainTargetGuidMethod.Invoke(proj, null);
                unityFrameworkTarget = (string)unityFrameworkTargetGuidMethod.Invoke(proj, null);
            }
            else
            {
                mainTarget           = proj.TargetGuidByName("Unity-iPhone");
                unityFrameworkTarget = mainTarget;
            }

            var settings = UnityNotificationEditorManager.Initialize().iOSNotificationEditorSettingsFlat;

            var addPushNotificationCapability = (bool)settings
                                                .Find(i => i.key == "UnityAddRemoteNotificationCapability").val == true;;

            var needLocationFramework = (bool)settings
                                        .Find(i => i.key == "UnityUseLocationNotificationTrigger").val == true;;

            proj.AddFrameworkToProject(unityFrameworkTarget, "UserNotifications.framework", true);

            if (needLocationFramework)
            {
                proj.AddFrameworkToProject(unityFrameworkTarget, "CoreLocation.framework", false);
            }

            File.WriteAllText(projPath, proj.WriteToString());

            if (addPushNotificationCapability)
            {
                var useReleaseAPSEnvSetting = settings
                                              .Find(i => i.key == "UnityUseAPSReleaseEnvironment");
                var useReleaseAPSEnv = false;

                if (useReleaseAPSEnvSetting != null)
                {
                    useReleaseAPSEnv = (bool)useReleaseAPSEnvSetting.val;
                }

                var entitlementsFileName = proj.GetBuildPropertyForConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS");

                if (entitlementsFileName == null)
                {
                    var bundleIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
                    entitlementsFileName = string.Format("{0}.entitlements",
                                                         bundleIdentifier.Substring(bundleIdentifier.LastIndexOf(".") + 1));
                }

                var pbxPath    = PBXProject.GetPBXProjectPath(path);
                var capManager = new ProjectCapabilityManager(pbxPath, entitlementsFileName, "Unity-iPhone");
                capManager.AddPushNotifications(!useReleaseAPSEnv);
                capManager.WriteToFile();
            }

            // Get plist
            var plistPath = path + "/Info.plist";
            var plist     = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plistPath));

            // Get root
            var rootDict = plist.root;

            var  requiredVersion = new Version(8, 0);
            bool hasMinOSVersion;

            try
            {
                var currentVersion = new Version(PlayerSettings.iOS.targetOSVersionString);
                hasMinOSVersion = currentVersion >= requiredVersion;
            }
            catch (Exception)
            {
                hasMinOSVersion = false;
            }

            if (!hasMinOSVersion)
            {
                Debug.Log("UserNotifications are only available on iOSSettings 10 and above, please make sure that you set a correct `Target minimum iOSSettings Version` in Player Settings.");
            }

            foreach (var setting in settings)
            {
                if (setting.val.GetType() == typeof(bool))
                {
                    rootDict.SetBoolean(setting.key, (bool)setting.val);
                }
                else if (setting.val.GetType() == typeof(PresentationOption) || setting.val.GetType() == typeof(AuthorizationOption))
                {
                    rootDict.SetInteger(setting.key, (int)setting.val);
                }
            }

            if (addPushNotificationCapability)
            {
                PlistElementArray currentBacgkgroundModes = (PlistElementArray)rootDict["UIBackgroundModes"];

                if (currentBacgkgroundModes == null)
                {
                    currentBacgkgroundModes = rootDict.CreateArray("UIBackgroundModes");
                }

                currentBacgkgroundModes.AddString("remote-notification");
            }

            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());

            //Get Preprocessor.h
            var preprocessorPath = path + "/Classes/Preprocessor.h";
            var preprocessor     = File.ReadAllText(preprocessorPath);

            if (needLocationFramework)
            {
                if (preprocessor.Contains("UNITY_USES_LOCATION"))
                {
                    preprocessor = preprocessor.Replace("UNITY_USES_LOCATION 0", "UNITY_USES_LOCATION 1");
                }
            }

            preprocessor = preprocessor.Replace("UNITY_USES_REMOTE_NOTIFICATIONS 0", "UNITY_USES_REMOTE_NOTIFICATIONS 1");
            File.WriteAllText(preprocessorPath, preprocessor);
        }
                #endif
    }
Exemple #16
0
        private static void PostProcessXCodeProject(string path)
        {
            Debug.Log("Post Process X Code Project");

            var settings = GetBuildSettings();

            if (settings.EnablePostProcessXCodeProject == false)
            {
                Debug.Log("[HovelHouse.CloudKit] skipping post process build step...");
                return;
            }

            Debug.Log("[HovelHouse.CloudKit] " + path);

            // When building a MacOS xCode project, unity's GetPBXProjectPath
            // returns the wrong pbxproject path
#if UNITY_STANDALONE_OSX && UNITY_2019_3_OR_NEWER
            string pbxPath = Path.Combine(path, "./project.pbxproj");
#else
            string pbxPath = PBXProject.GetPBXProjectPath(path);
#endif
            var pbxProject = new PBXProject();
            pbxProject.ReadFromFile(pbxPath);

            var name = PlayerSettings.applicationIdentifier.Split('.').Last();


#if UNITY_2019_3_OR_NEWER
            // On MacOS GetUnityManTargetGuid returns null - so we have to look it up by name
            // but honestly, doesn't even look like the ProjectCapabilityManager is doing anything
            // on MacOS
#if UNITY_STANDALONE_OSX
            string targetGUID           = pbxProject.TargetGuidByName(name);
            string entitlementsFilename = name + "/" + name + ".entitlements";
#else
            string targetGUID           = pbxProject.GetUnityMainTargetGuid();
            string entitlementsFilename = name + ".entitlements";
#endif
            if (string.IsNullOrEmpty(targetGUID))
            {
                throw new BuildFailedException("unable to find the GUID of the build target");
            }

            ProjectCapabilityManager projCapability = new ProjectCapabilityManager(
                pbxPath, entitlementsFilename, null, targetGUID);
#else
            string entitlementsFilename             = name + ".entitlements";
            ProjectCapabilityManager projCapability = new ProjectCapabilityManager(
                pbxPath, entitlementsFilename, PBXProject.GetUnityTargetName());
#endif

            projCapability.AddiCloud(
                settings.EnableKeyVaueStorage,
                settings.EnableDocumentStorage,
                settings.EnableCloudKit,
                settings.AddDefaultContainers,
                settings.CustomContainers);

            if (settings.EnableCloudKitNotifications)
            {
                projCapability.AddPushNotifications(settings.apsEnvironment == APSEnvironment.Development);
                projCapability.AddBackgroundModes((BackgroundModesOptions)settings.BackgroundModes);
            }

            projCapability.WriteToFile();
        }
Exemple #17
0
        private static void AddCapabilities(ProjectCapabilityManager capManager)
        {
            var capability = ISD_Settings.Instance.Capability;

            if (capability.iCloud.Enabled)
            {
                if (capability.iCloud.iCloudDocument || capability.iCloud.customContainers.Count > 0)
                {
                    capManager.AddiCloud(capability.iCloud.keyValueStorage, capability.iCloud.iCloudDocument, capability.iCloud.customContainers.ToArray());
                }
                else
                {
                    capManager.AddiCloud(capability.iCloud.keyValueStorage, false, null);
                }
            }

            if (capability.PushNotifications.Enabled)
            {
                capManager.AddPushNotifications(capability.PushNotifications.development);
            }

            if (capability.GameCenter.Enabled)
            {
                capManager.AddGameCenter();
            }

            if (capability.Wallet.Enabled)
            {
                capManager.AddWallet(capability.Wallet.passSubset.ToArray());
            }

            if (capability.Siri.Enabled)
            {
                capManager.AddSiri();
            }

            if (capability.ApplePay.Enabled)
            {
                capManager.AddApplePay(capability.ApplePay.merchants.ToArray());
            }

            if (capability.InAppPurchase.Enabled)
            {
                capManager.AddInAppPurchase();
            }

            if (capability.Maps.Enabled)
            {
                var options = MapsOptions.None;
                foreach (var opt in capability.Maps.options)
                {
                    MapsOptions opt2 = (MapsOptions)opt;
                    options |= opt2;
                }
                capManager.AddMaps(options);
            }

            if (capability.PersonalVPN.Enabled)
            {
                capManager.AddPersonalVPN();
            }

            if (capability.BackgroundModes.Enabled)
            {
                var options = BackgroundModesOptions.None;
                foreach (var opt in capability.BackgroundModes.options)
                {
                    BackgroundModesOptions opt2 = (BackgroundModesOptions)opt;
                    options |= opt2;
                }
                capManager.AddBackgroundModes(options);
            }


            if (capability.InterAppAudio.Enabled)
            {
                capManager.AddInterAppAudio();
            }

            if (capability.KeychainSharing.Enabled)
            {
                capManager.AddKeychainSharing(capability.KeychainSharing.accessGroups.ToArray());
            }

            if (capability.AssociatedDomains.Enabled)
            {
                capManager.AddAssociatedDomains(capability.AssociatedDomains.domains.ToArray());
            }

            if (capability.AppGroups.Enabled)
            {
                capManager.AddAppGroups(capability.AppGroups.groups.ToArray());
            }

            if (capability.DataProtection.Enabled)
            {
                capManager.AddDataProtection();
            }

            if (capability.HomeKit.Enabled)
            {
                capManager.AddHomeKit();
            }

            if (capability.HealthKit.Enabled)
            {
                capManager.AddHealthKit();
            }

            if (capability.WirelessAccessoryConfiguration.Enabled)
            {
                capManager.AddWirelessAccessoryConfiguration();
            }
        }
        public static void OnPostprocessBuild(BuildTarget build_target, string path)
        {
            if (build_target != BuildTarget.iOS) return;

            string proj_path = PBXProject.GetPBXProjectPath(path);
            PBXProject proj = new PBXProject();
            proj.ReadFromString(File.ReadAllText(proj_path));

            // 获取当前项目名字
            string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());

            // 对所有的编译配置设置选项
            proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");

            // 添加依赖库
            proj.AddFrameworkToProject(target, "libc++.dylib", false);
            proj.AddFrameworkToProject(target, "libsqlite3.dylib", false);
            proj.AddFrameworkToProject(target, "libz.dylib", false);

            proj.AddFrameworkToProject(target, "libc++.tbd", false);
            proj.AddFrameworkToProject(target, "libicucore.tbd", false);
            proj.AddFrameworkToProject(target, "libsqlite3.tbd", false);
            proj.AddFrameworkToProject(target, "libz.tbd", false);
            proj.AddFrameworkToProject(target, "libz.1.2.5.tbd", false);

            proj.AddFrameworkToProject(target, "Accelerate.framework", false);
            proj.AddFrameworkToProject(target, "AudioToolbox.framework", false);
            proj.AddFrameworkToProject(target, "AVFoundation.framework", false);
            proj.AddFrameworkToProject(target, "CFNetwork.framework", false);
            proj.AddFrameworkToProject(target, "CoreLocation.framework", false);
            proj.AddFrameworkToProject(target, "CoreMedia.framework", false);
            proj.AddFrameworkToProject(target, "CoreMotion.framework", false);
            proj.AddFrameworkToProject(target, "CoreTelephony.framework", false);
            proj.AddFrameworkToProject(target, "CoreVideo.framework", false);
            proj.AddFrameworkToProject(target, "JavaScriptCore.framework", true);// 设置为Optional
            proj.AddFrameworkToProject(target, "MessageUI.framework", false);
            proj.AddFrameworkToProject(target, "MobileCoreServices.framework", false);
            proj.AddFrameworkToProject(target, "PushKit.framework", true);
            proj.AddFrameworkToProject(target, "Security.framework", false);// 用于存储keychain
            proj.AddFrameworkToProject(target, "SystemConfiguration.framework", false);// 用于读取异常发生时的系统信息
            proj.AddFrameworkToProject(target, "UserNotifications.framework", true);

            // 设置签名
            //proj.SetBuildProperty (target, "CODE_SIGN_IDENTITY", "iPhone Distribution: _______________");
            //proj.SetBuildProperty (target, "PROVISIONING_PROFILE", "********-****-****-****-************");
            //string debugConfig = proj.BuildConfigByName(target, "Debug");
            //string releaseConfig = proj.BuildConfigByName(target, "Release");

            //proj.SetBuildPropertyForConfig(debugConfig, "PROVISIONING_PROFILE", "证书");
            //proj.SetBuildPropertyForConfig(releaseConfig, "PROVISIONING_PROFILE", "证书");
            //proj.SetBuildPropertyForConfig(debugConfig, "PROVISIONING_PROFILE(Deprecated)", "证书");
            //proj.SetBuildPropertyForConfig(releaseConfig, "PROVISIONING_PROFILE(Deprecated)", "证书");

            //proj.SetBuildPropertyForConfig(debugConfig, "CODE_SIGN_IDENTITY", "自己的证书");
            //proj.SetBuildPropertyForConfig(releaseConfig, "CODE_SIGN_IDENTITY", "自己的证书");

            //proj.SetTeamId(target, "Team ID(自己的teamid)");

            //proj.AddCapability(target, PBXCapabilityType.AssociatedDomains);

            // 保存工程
            proj.WriteToFile(proj_path);

            ProjectCapabilityManager proj_capability_mgr = new ProjectCapabilityManager(proj_path, "KingNative.entitlements", PBXProject.GetUnityTargetName());
            proj_capability_mgr.AddAssociatedDomains(new string[] { "applinks:znc4d4.openinstall.io" });// OpenInstall
            proj_capability_mgr.AddPushNotifications(false);
            proj_capability_mgr.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
            proj_capability_mgr.WriteToFile();

            // 修改plist
            string plist_path = path + "/Info.plist";
            PlistDocument plist = new PlistDocument();
            plist.ReadFromString(File.ReadAllText(plist_path));
            PlistElementDict root_dict = plist.root;
            root_dict.SetString("com.openinstall.APP_KEY", "znc4d4");// OpenInstall
            // NativeToolkit
            root_dict.SetString("NSPhotoLibraryUsageDescription", "Requires access to the Photo Library");
            root_dict.SetString("NSPhotoLibraryAddUsageDescription", "Requires access to the Photo Library");
            root_dict.SetString("NSCameraUsageDescription", "Requires access to the Camera");
            root_dict.SetString("NSContactsUsageDescription", "Requires access to Contacts");
            root_dict.SetString("NSLocationAlwaysUsageDescription", "Requires access to Location");
            root_dict.SetString("NSLocationWhenInUseUsageDescription", "Requires access to Location");
            root_dict.SetString("NSLocationAlwaysAndWhenInUseUsageDescription", "Requires access to Location");

            // 保存plist
            plist.WriteToFile(plist_path);
#endif
        }
        protected override void OnPostProcessBuild(string playerPath)
        {
#if UNITY_IOS
            string projPath = Path.Combine(playerPath, "Unity-iPhone.xcodeproj/project.pbxproj");

            PBXProject proj = new PBXProject();
            proj.ReadFromFile(projPath);

            string target = proj.TargetGuidByName("Unity-iPhone");

            proj.SetBuildProperty(target, "ENABLE_BITCODE", m_EnableBitcode ? "YES" : "NO");

            if (string.IsNullOrEmpty(m_AppleDeveloperTeamId))
            {
                proj.SetBuildProperty(target, "DEVELOPMENT_TEAM", m_AppleDeveloperTeamId);
            }

            for (int i = 0; i < m_Frameworks.Length; i++)
            {
                var s = m_Frameworks[i];
                proj.AddFrameworkToProject(target, s, true);
            }

            for (int i = 0; i < m_Files.Length; i++)
            {
                var s = m_Files[i];
                proj.AddFileToBuild(target, proj.AddFile(Path.Combine("usr/lib/", s.Name), Path.Combine("Frameworks/", s.Name), (PBXSourceTree)s.SourceTree));
            }

            proj.WriteToFile(projPath);

            string        plistPath = Path.Combine(playerPath, "Info.plist");
            PlistDocument plist     = new PlistDocument();
            plist.ReadFromFile(plistPath);
            PlistElementDict root = plist.root;

            for (int i = 0; i < m_InfoPlistEntries.Length; i++)
            {
                InfoPlistEntry entry = m_InfoPlistEntries[i];

                switch (entry.Type)
                {
                case PlistEntryType.Boolean:
                    root.SetBoolean(entry.Key, entry.BooleanValue);
                    break;

                case PlistEntryType.Integer:
                    root.SetInteger(entry.Key, entry.IntegerValue);
                    break;

                case PlistEntryType.String:
                    root.SetString(entry.Key, entry.StringValue);
                    break;
                }
            }

            plist.WriteToFile(plistPath);

            var capabilityManager = new ProjectCapabilityManager(projPath, "Unity-iPhone/app.entitlements", "Unity-iPhone");

            if (m_EnableGameCenter)
            {
                capabilityManager.AddGameCenter();
            }

            if (m_EnableInAppPurchase)
            {
                capabilityManager.AddInAppPurchase();
            }

            if (m_EnableKeychainSharing)
            {
                capabilityManager.AddKeychainSharing(m_KeychainAccessGroups);
            }

            if (m_EnablePushNotifications)
            {
                capabilityManager.AddPushNotifications(m_PushNotificationsDevelopment);
            }

            capabilityManager.WriteToFile();
#endif
        }