Ejemplo n.º 1
0
 private static void OnPostprocessInfo(PlistDocumentWrapper info, AppCenterSettings settings)
 {
     if ((settings.UseAuth && AppCenter.Auth != null) || (settings.UseDistribute && AppCenter.Distribute != null))
     {
         // Add App Center URL sceme.
         var root     = info.GetRoot();
         var urlTypes = root.GetType().GetMethod("CreateArray").Invoke(root, new object[] { "CFBundleURLTypes" });
         if (settings.UseAuth && AppCenter.Auth != null)
         {
             var urlType         = urlTypes.GetType().GetMethod("AddDict").Invoke(urlTypes, null);
             var setStringMethod = urlType.GetType().GetMethod("SetString");
             setStringMethod.Invoke(urlType, new object[] { "CFBundleTypeRole", "Editor" });
             setStringMethod.Invoke(urlType, new object[] { "CFBundleURLName", "$(PRODUCT_BUNDLE_IDENTIFIER)" });
             var urlSchemes = urlType.GetType().GetMethod("CreateArray").Invoke(urlType, new[] { "CFBundleURLSchemes" });
             urlSchemes.GetType().GetMethod("AddString").Invoke(urlSchemes, new[] { "msal" + settings.iOSAppSecret });
         }
         if (settings.UseDistribute && AppCenter.Distribute != null)
         {
             var urlType         = urlTypes.GetType().GetMethod("AddDict").Invoke(urlTypes, null);
             var setStringMethod = urlType.GetType().GetMethod("SetString");
             setStringMethod.Invoke(urlType, new object[] { "CFBundleTypeRole", "None" });
             setStringMethod.Invoke(urlType, new object[] { "CFBundleURLName", ApplicationIdHelper.GetApplicationId() });
             var urlSchemes = urlType.GetType().GetMethod("CreateArray").Invoke(urlType, new[] { "CFBundleURLSchemes" });
             urlSchemes.GetType().GetMethod("AddString").Invoke(urlSchemes, new[] { "appcenter-" + settings.iOSAppSecret });
         }
     }
 }
Ejemplo n.º 2
0
    static void UpdateJson()
    {
#if UNITY_ANDROID
        var bundleId            = ApplicationIdHelper.GetApplicationId();
        var projectDir          = Path.Combine(Application.dataPath, "..");
        var googleServicesFiles = FindGoogleServicesFiles();
        if (googleServicesFiles == null)
        {
            return;
        }
        if (googleServicesFiles.Length > 1)
        {
            Debug.LogWarning("More than one " + GoogleServicesInputFile + " file found, using first one.");
        }
        var inputPath  = Path.Combine(projectDir, googleServicesFiles[0]);
        var outputPath = Path.Combine(projectDir, GoogleServicesOutputPath);
        var outputDir  = Path.Combine(projectDir, GoogleServicesOutputDirectory);
        if (!Directory.Exists(outputDir))
        {
            try
            {
                Directory.CreateDirectory(outputDir);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                return;
            }
        }
        if (File.Exists(outputPath) &&
            File.GetLastWriteTime(outputPath).CompareTo(File.GetLastWriteTime(inputPath)) >= 0)
        {
            return;
        }
        var json               = File.ReadAllText(inputPath);
        var googleServices     = JsonUtility.FromJson <GoogleServices>(json);
        var resolvedClientInfo = googleServices.GetClient(bundleId);
        if (resolvedClientInfo == null)
        {
            Debug.LogWarning("Failed to find client_info in " + GoogleServicesInputFile + " matching package name: " + bundleId);
        }
        var valuesItems = new Dictionary <string, string> {
            { DefaultWebClientIdKey, googleServices.GetDefaultWebClientId(bundleId) },
            { FirebaseDatabaseUrlKey, googleServices.GetFirebaseDatabaseUrl() },
            { GATrackingIdKey, googleServices.GetGATrackingId(bundleId) },
            { GSMDefaultSenderIdKey, googleServices.GetDefaultGcmSenderId() },
            { GoogleAPIKey, googleServices.GetGoogleApiKey(bundleId) },
            { GoogleAppIdKey, googleServices.GetGoogleAppId(bundleId) },
            { CrashReportingApiKey, googleServices.GetCrashReportingApiKey(bundleId) },
            { GoogleStorageBucketKey, googleServices.GetStorageBucket(bundleId) },
            { ProjectIdKey, googleServices.GetProjectId() },
        };
        XmlResourceHelper.WriteXmlResource(outputPath, valuesItems);
        // Update editor project view.
        AssetDatabase.Refresh();
#endif
    }
Ejemplo n.º 3
0
    private static void OnPostprocessInfo(PlistDocumentWrapper info, AppCenterSettings settings)
    {
        if (settings.UseDistribute && AppCenter.Distribute != null)
        {
            // Add App Center URL scemes.
            var schemes = new List <string>()
            {
                "appcenter-" + settings.iOSAppSecret
            };

            // Create a reflection call for getting custom schemes from iOS settings.
            var playerSettingsClass = typeof(PlayerSettings.iOS);
            var iOSURLSchemesMethod = playerSettingsClass.GetMethod("GetURLSchemes", BindingFlags.Static | BindingFlags.NonPublic);

            // Verify that method exists and call it for getting custom schemes.
            if (iOSURLSchemesMethod != null)
            {
                var schemesFromSettings = (string[])iOSURLSchemesMethod.Invoke(null, null);
                schemes.AddRange(schemesFromSettings.ToList <string>());
            }

            // Generate scheme information.
            var root     = info.GetRoot();
            var urlTypes = root.GetType().GetMethod("CreateArray").Invoke(root, new object[] { "CFBundleURLTypes" });
            if (settings.UseDistribute && AppCenter.Distribute != null)
            {
                var urlType         = urlTypes.GetType().GetMethod("AddDict").Invoke(urlTypes, null);
                var setStringMethod = urlType.GetType().GetMethod("SetString");
                setStringMethod.Invoke(urlType, new object[] { "CFBundleTypeRole", "None" });
                setStringMethod.Invoke(urlType, new object[] { "CFBundleURLName", ApplicationIdHelper.GetApplicationId() });
                var urlSchemes = urlType.GetType().GetMethod("CreateArray").Invoke(urlType, new[] { "CFBundleURLSchemes" });

                // Add custom schemes defined in Unity players settings.
                foreach (var scheme in schemes)
                {
                    urlSchemes.GetType().GetMethod("AddString").Invoke(urlSchemes, new[] { scheme });
                }
            }
        }
    }