Пример #1
0
        private static void CopyRawSettingsFile(string rootPath, PBXProject project, string target, CASInitSettings casSettings)
        {
            if (!casSettings)
            {
                return;
            }

            var resourcesBuildPhase = project.GetResourcesBuildPhaseByTarget(target);

            for (int i = 0; i < casSettings.managersCount; i++)
            {
                string managerId       = casSettings.GetManagerId(i);
                int    managerIdLength = managerId.Length;
                string suffixChar      = char.ToLower(managerId[managerIdLength - 1]).ToString();
                string fileName        = "cas_settings" + managerIdLength.ToString() + suffixChar + ".json";
                string pathInAssets    = CASEditorUtils.GetNativeSettingsPath(BuildTarget.iOS, managerId);
                if (File.Exists(pathInAssets))
                {
                    try
                    {
                        File.Copy(pathInAssets, Path.Combine(rootPath, fileName), true);
                        var fileGuid = project.AddFile(fileName, fileName, PBXSourceTree.Source);
                        project.AddFileToBuildSection(target, resourcesBuildPhase, fileGuid);
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(CASEditorUtils.logTag + "Copy Raw File To XCode Project failed: " + e.ToString());
                    }
                }
                else
                {
                    Debug.Log(CASEditorUtils.logTag + "Not found Raw file: " + pathInAssets);
                }
            }
        }
Пример #2
0
        private static void ApplyCrosspromoDynamicLinks(string buildPath, string targetGuid, CASInitSettings casSettings, DependencyManager deps)
        {
            if (!casSettings || casSettings.IsTestAdMode() || casSettings.managersCount == 0 ||
                string.IsNullOrEmpty(casSettings.GetManagerId(0)))
            {
                return;
            }
            if (deps != null)
            {
                var crossPromoDependency = deps.FindCrossPromotion();
                if (crossPromoDependency != null && !crossPromoDependency.IsInstalled())
                {
                    return;
                }
            }
            try
            {
                var identifier   = Application.identifier;
                var productName  = identifier.Substring(identifier.LastIndexOf(".") + 1);
                var projectPath  = GetXCodeProjectPath(buildPath);
                var entitlements = new ProjectCapabilityManager(projectPath, productName + ".entitlements",
#if UNITY_2019_3_OR_NEWER
                                                                null, targetGuid);
#else
                                                                PBXProject.GetUnityTargetName());
#endif
                string link = "applinks:psvios" + casSettings.GetManagerId(0) + ".page.link";
                entitlements.AddAssociatedDomains(new[] { link });
                entitlements.WriteToFile();
                Debug.Log(CASEditorUtils.logTag + "Apply application shame: " + link);
            }
            catch (Exception e)
            {
                Debug.LogError(CASEditorUtils.logTag + "Dynamic link creation fail: " + e.ToString());
            }
        }
        private static void ConfigureAndroid(CASInitSettings settings, CASEditorSettings editorSettings, string admobAppId)
        {
#if UNITY_ANDROID || CASDeveloper
            EditorUtility.DisplayProgressBar(casTitle, "Validate CAS Android Build Settings", 0.8f);

            const string deprecatedPluginPath = "Assets/Plugins/CAS";
            if (AssetDatabase.IsValidFolder(deprecatedPluginPath))
            {
                AssetDatabase.DeleteAsset(deprecatedPluginPath);
                Debug.Log("Removed deprecated plugin: " + deprecatedPluginPath);
            }

            HashSet <string> promoAlias = new HashSet <string>();
            if (editorSettings.generateAndroidQuerriesForPromo)
            {
                for (int i = 0; i < settings.managersCount; i++)
                {
                    Utils.GetCrossPromoAlias(BuildTarget.Android, settings.GetManagerId(i), promoAlias);
                }
            }

            UpdateAndroidPluginManifest(admobAppId, promoAlias, editorSettings);

            CASPreprocessGradle.Configure(editorSettings);

#if !UNITY_2021_2_OR_NEWER
            // 19 - AndroidSdkVersions.AndroidApiLevel19
            // Deprecated in Unity 2021.2
            if (PlayerSettings.Android.minSdkVersion < ( AndroidSdkVersions )19)
            {
                Utils.DialogOrCancelBuild("CAS required a higher minimum SDK API level. Set SDK level 19 (KitKat) and continue?", BuildTarget.NoTarget);
                PlayerSettings.Android.minSdkVersion = ( AndroidSdkVersions )19;
            }
#endif
#endif
        }
        private static string UpdateRemoteSettingsAndGetAppId(CASInitSettings settings, BuildTarget platform, DependencyManager deps)
        {
            string appId = null;
            string updateSettingsError = "";

            for (int i = 0; i < settings.managersCount; i++)
            {
                var managerId = settings.GetManagerId(i);
                if (managerId == null || managerId.Length < 5)
                {
                    continue;
                }
                try
                {
                    string newAppId = DownloadRemoteSettings(managerId, platform, settings, deps);
                    if (!string.IsNullOrEmpty(appId) || string.IsNullOrEmpty(newAppId))
                    {
                        continue;
                    }
                    if (newAppId.Contains('~'))
                    {
                        appId = newAppId;
                        continue;
                    }
                    if (i == 0)
                    {
                        Debug.LogError(Utils.logTag + "CAS id [" + managerId +
                                       "] has an error in server settings. Please contact support!");
                    }
                }
                catch (Exception e)
                {
                    updateSettingsError = e.Message;
                }
            }
            if (!string.IsNullOrEmpty(appId) || settings.IsTestAdMode())
            {
                return(appId);
            }

            const string title          = "Update CAS remote settings";
            int          dialogResponse = 0;
            var          targetId       = settings.GetManagerId(0);

            var message = updateSettingsError +
                          "\nPlease try using a real identifier in the first place else contact support." +
                          "\n- Warning! -" +
                          "\n1. Continue build the app for release with current settings can reduce monetization revenue." +
                          "\n2. When build to testing your app, make sure you use Test Ads mode rather than live ads. " +
                          "Failure to do so can lead to suspension of your account.";

            Debug.LogError(Utils.logTag + message);
            if (!Application.isBatchMode)
            {
                dialogResponse = EditorUtility.DisplayDialogComplex(title, message,
                                                                    "Continue", "Cancel Build", "Select settings file");
            }

            if (dialogResponse == 0)
            {
                var cachePath = Utils.GetNativeSettingsPath(platform, targetId);
                if (File.Exists(cachePath))
                {
                    return(Utils.GetAdmobAppIdFromJson(File.ReadAllText(cachePath)));
                }
                return(null);
            }
            if (dialogResponse == 1)
            {
                Utils.StopBuildWithMessage("Build canceled", BuildTarget.NoTarget);
                return(null);
            }
            return(Utils.SelectSettingsFileAndGetAppId(targetId, platform));
        }
Пример #5
0
        private static void UpdateGADAppId(PlistDocument plist, CASInitSettings initSettings, DependencyManager deps)
        {
            if (!initSettings)
            {
                return;
            }
            #region Read Admob App ID from CAS Settings
            bool admobAppIdRequired = deps == null;
            if (deps != null)
            {
                var admobDep = deps.Find(AdNetwork.GoogleAds);
                if (admobDep != null)
                {
                    admobAppIdRequired = admobDep.IsInstalled();
                }
            }

            string admobAppId = null;
            if (initSettings.managersCount > 0)
            {
                string settingsPath = CASEditorUtils.GetNativeSettingsPath(BuildTarget.iOS, initSettings.GetManagerId(0));
                if (File.Exists(settingsPath))
                {
                    try
                    {
                        admobAppId = CASEditorUtils.GetAdmobAppIdFromJson(File.ReadAllText(settingsPath));
                    }
                    catch (Exception e)
                    {
                        if (!initSettings.IsTestAdMode() && admobAppIdRequired)
                        {
                            CASEditorUtils.StopBuildWithMessage(e.ToString(), BuildTarget.iOS);
                        }
                    }
                }
            }
            if (string.IsNullOrEmpty(admobAppId) && initSettings.IsTestAdMode())
            {
                admobAppId = CASEditorUtils.iosAdmobSampleAppID;
            }

            #endregion

            if (!string.IsNullOrEmpty(admobAppId))
            {
                plist.root.SetString("GADApplicationIdentifier", admobAppId);
            }
        }