Skip to content

Commit

Permalink
Merge pull request #469 from microsoft/fix/add-custom-schemes
Browse files Browse the repository at this point in the history
App Center post-build does not override custom URL Scheme
  • Loading branch information
MatkovIvan authored Sep 14, 2020
2 parents 493e229 + ce64d9d commit 96bf42c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Assets/AppCenter/Editor/AppCenterPostBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityEditor.Build;
using UnityEditor;
using UnityEngine;
using System.Reflection;

// Warning: Don't use #if #endif for conditional compilation here as Unity
// doesn't always set the flags early enough.
Expand Down Expand Up @@ -419,7 +420,21 @@ private static void OnPostprocessInfo(PlistDocumentWrapper info, AppCenterSettin
{
if (settings.UseDistribute && AppCenter.Distribute != null)
{
// Add App Center URL sceme.
// 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)
Expand All @@ -429,7 +444,12 @@ private static void OnPostprocessInfo(PlistDocumentWrapper info, AppCenterSettin
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 });

// Add custom schemes defined in Unity players settings.
foreach (var scheme in schemes)
{
urlSchemes.GetType().GetMethod("AddString").Invoke(urlSchemes, new[] { scheme });
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# App Center SDK for Unity Change Log

## Release 3.3.1 (Under development)

### App Center

#### iOS

* **[Fix]** Fix overriding custom `URLScheme` in the post-build script.

___

## Release 3.3.0

This version has a breaking change on iOS - it drops Xcode 10 support, Xcode 11 is a minimal supported version now.
Expand Down

0 comments on commit 96bf42c

Please sign in to comment.