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
    void PostprocessFortvOSiOS(string path)
    {
        // Read in the Xcode project
        var        projPath = PBXProject.GetPBXProjectPath(path);
        PBXProject proj     = new PBXProject();

        proj.ReadFromFile(projPath);

        // Get the main target GUID
    #if UNITY_2019_3_OR_NEWER
        var mainTarget = proj.GetUnityMainTargetGuid();
    #else
        var mainTarget = proj.TargetGuidByName("Unity-iPhone");
    #endif
        var entitlementsFile = $"{Application.productName}.entitlements";

        string entitlementsFileName = proj.GetBuildPropertyForAnyConfig(new [] {
            mainTarget
        }, "CODE_SIGN_ENTITLEMENTS");


        // If the project has an entitlements file path set, use it
        if (entitlementsFileName != null)
        {
            entitlementsFile = entitlementsFileName;

            string[] entitlementsFiles = Directory.GetFiles(path, Path.GetFileName(entitlementsFileName), SearchOption.AllDirectories);

            // If that file exists and we're appending the build then copy it to the staging area
            // so we can save the existing entitlements
            if (entitlementsFiles.Length > 0)
            {
                entitlementsFile = entitlementsFileName;
            }
        }

#if UNITY_2019_3_OR_NEWER
        // AuthenticationServices should be added to the Framework target on Unity 2019.3+
        proj.AddFrameworkToProject(proj.GetUnityFrameworkTargetGuid(), "AuthenticationServices.framework", false);
        proj.WriteToFile(projPath);

        // Finally add the capability and entitlement to the project
        // Note: The function AddSignInWithApple was added in 2018.4.12f1, 2019.2.11f1 and 2019.3.0.
        // If you see an error make sure that your editor version is at or above one of those versions.
        var capManager = new ProjectCapabilityManager(projPath, entitlementsFile, targetGuid: mainTarget);
#else
        var capManager = new ProjectCapabilityManager(projPath, entitlementsFile, "Unity-iPhone");
#endif

        capManager.AddSignInWithApple();
        capManager.WriteToFile();
    }
        public void OnPostprocessBuild(BuildReport report)
        {
            // Clean and reset settings after builds to make sure we don't
            // pollute later builds with assets that may be unnecessary or are outdated.
            CleanOldSettings();
#if (UNITY_IOS || UNITY_TVOS) && UNITY_2019_2
            PBXProject proj        = new PBXProject();
            string     pbxFilename = report.summary.outputPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
            proj.ReadFromFile(pbxFilename);

            var targetName  = PBXProject.GetUnityTargetName();
            var targetBuild = proj.TargetGuidByName(name: targetName);
            proj.AddFrameworkToProject(targetBuild, "AuthenticationServices.framework", false);
            proj.WriteToFile(pbxFilename);
#endif
#if (UNITY_IOS || UNITY_TVOS) && UNITY_2019_3_OR_NEWER
            PBXProject proj        = new PBXProject();
            string     pbxFilename = report.summary.outputPath + "/Unity-iPhone.xcodeproj/project.pbxproj";
            proj.ReadFromFile(pbxFilename);

            // The framework needs to be on the framework target rather than the main target as the capability manager does
            string frameworkTarget = proj.GetUnityFrameworkTargetGuid();
            proj.AddFrameworkToProject(frameworkTarget, "AuthenticationServices.framework", false);

            string mainTarget = proj.GetUnityMainTargetGuid();

            // Check if the project has an existing entitlements file path set
            string entitlementsFileName = proj.GetBuildPropertyForAnyConfig(mainTarget, "CODE_SIGN_ENTITLEMENTS");
            if (entitlementsFileName == null)
            {
                entitlementsFileName = report.summary.outputPath + string.Format("/{0}.entitlements", PlayerSettings.productName);
            }

            proj.WriteToFile(pbxFilename);

            var identitySettings  = GetPlayerIdentityGeneralSettings(EditorUserBuildSettings.selectedBuildTargetGroup);
            var appleLoaderExists =
                identitySettings?.Manager?.providerLoaders?.Exists(x => x.GetType() == typeof(AppleLoader));
            if (appleLoaderExists == null || !(bool)appleLoaderExists)
            {
                return;
            }
            var capManager = new ProjectCapabilityManager(pbxFilename, entitlementsFileName, targetGuid: mainTarget);
            capManager.AddSignInWithApple();
            capManager.WriteToFile();
#endif
        }
Exemple #4
0
        public static void OnPostProcessBuild(BuildTarget target, string path)
        {
            if (target != BuildTarget.iOS)
            {
                return;
            }

            var projectPath = PBXProject.GetPBXProjectPath(path);

#if UNITY_2019_3_OR_NEWER
            var project = new PBXProject();
            project.ReadFromString(System.IO.File.ReadAllText(projectPath));
            var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", targetGuid: project.GetUnityMainTargetGuid());
#else
            var manager = new ProjectCapabilityManager(projectPath, "Entitlements.entitlements", PBXProject.GetUnityTargetName());
#endif
            manager.AddSignInWithApple();
            manager.WriteToFile();
        }
Exemple #5
0
        static void AddCapabilities(ProjectCapabilityManager capManager)
        {
            var capability = XCodeProjectSettings.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 UNITY_2019_3_OR_NEWER
            if (capability.SignInWithApple.Enabled)
            {
                capManager.AddSignInWithApple();
            }
#endif

            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)
                {
                    var 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)
                {
                    var 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();
            }
        }