Skip to content

Commit 96bf42c

Browse files
authored
Merge pull request #469 from microsoft/fix/add-custom-schemes
App Center post-build does not override custom URL Scheme
2 parents 493e229 + ce64d9d commit 96bf42c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Assets/AppCenter/Editor/AppCenterPostBuild.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using UnityEditor.Build;
1313
using UnityEditor;
1414
using UnityEngine;
15+
using System.Reflection;
1516

1617
// Warning: Don't use #if #endif for conditional compilation here as Unity
1718
// doesn't always set the flags early enough.
@@ -419,7 +420,21 @@ private static void OnPostprocessInfo(PlistDocumentWrapper info, AppCenterSettin
419420
{
420421
if (settings.UseDistribute && AppCenter.Distribute != null)
421422
{
422-
// Add App Center URL sceme.
423+
// Add App Center URL scemes.
424+
var schemes = new List<string>() { "appcenter-" + settings.iOSAppSecret };
425+
426+
// Create a reflection call for getting custom schemes from iOS settings.
427+
var playerSettingsClass = typeof(PlayerSettings.iOS);
428+
var iOSURLSchemesMethod = playerSettingsClass.GetMethod("GetURLSchemes", BindingFlags.Static | BindingFlags.NonPublic);
429+
430+
// Verify that method exists and call it for getting custom schemes.
431+
if (iOSURLSchemesMethod != null)
432+
{
433+
var schemesFromSettings = (string[])iOSURLSchemesMethod.Invoke(null, null);
434+
schemes.AddRange(schemesFromSettings.ToList<string>());
435+
}
436+
437+
// Generate scheme information.
423438
var root = info.GetRoot();
424439
var urlTypes = root.GetType().GetMethod("CreateArray").Invoke(root, new object[] { "CFBundleURLTypes" });
425440
if (settings.UseDistribute && AppCenter.Distribute != null)
@@ -429,7 +444,12 @@ private static void OnPostprocessInfo(PlistDocumentWrapper info, AppCenterSettin
429444
setStringMethod.Invoke(urlType, new object[] { "CFBundleTypeRole", "None" });
430445
setStringMethod.Invoke(urlType, new object[] { "CFBundleURLName", ApplicationIdHelper.GetApplicationId() });
431446
var urlSchemes = urlType.GetType().GetMethod("CreateArray").Invoke(urlType, new[] { "CFBundleURLSchemes" });
432-
urlSchemes.GetType().GetMethod("AddString").Invoke(urlSchemes, new[] { "appcenter-" + settings.iOSAppSecret });
447+
448+
// Add custom schemes defined in Unity players settings.
449+
foreach (var scheme in schemes)
450+
{
451+
urlSchemes.GetType().GetMethod("AddString").Invoke(urlSchemes, new[] { scheme });
452+
}
433453
}
434454
}
435455
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# App Center SDK for Unity Change Log
22

3+
## Release 3.3.1 (Under development)
4+
5+
### App Center
6+
7+
#### iOS
8+
9+
* **[Fix]** Fix overriding custom `URLScheme` in the post-build script.
10+
11+
___
12+
313
## Release 3.3.0
414

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

0 commit comments

Comments
 (0)