Skip to content

Commit 87d01af

Browse files
authored
Merge pull request #218 from lupidan/canary
v1.4.4 Release
2 parents 4731e04 + baee18b commit 87d01af

30 files changed

+797
-186
lines changed

.github/workflows/build-and-check.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on: workflow_dispatch
55
jobs:
66
Build-And-Check:
77
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
unity-version:
11+
- "6000.0.23f1"
12+
- "2022.3.51f1"
13+
- "2021.3.45f1"
14+
- "2020.3.48f1"
15+
816
steps:
917
- name: Checkout repository
1018
uses: actions/checkout@v3
@@ -18,11 +26,11 @@ jobs:
1826
with:
1927
projectPath: ./AppleAuthSampleProject
2028
targetPlatform: iOS
21-
unityVersion: 6000.0.23f1
29+
unityVersion: ${{ matrix.unity-version }}
2230

2331
- name: Upload Xcode artifact
2432
uses: actions/upload-artifact@v4
2533
with:
26-
name: 6000_0_3f1_XcodeBuild
34+
name: "${{ matrix.unity-version }}_XcodeBuild"
2735
path: build
2836

AppleAuth/AppleAuthManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if ((UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX) && !UNITY_EDITOR)
1+
#if ((UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS || UNITY_STANDALONE_OSX) && !UNITY_EDITOR)
22
#define APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
33
#endif
44

@@ -12,7 +12,7 @@ public class AppleAuthManager : IAppleAuthManager
1212
{
1313
static AppleAuthManager()
1414
{
15-
const string versionMessage = "Using Sign in with Apple Unity Plugin - v1.4.3";
15+
const string versionMessage = "Using Sign in with Apple Unity Plugin - v1.4.4";
1616
#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
1717
PInvoke.AppleAuth_LogMessage(versionMessage);
1818
#else
@@ -289,7 +289,7 @@ public Entry(bool isSingleUseCallback, Action<string> messageCallback)
289289

290290
private static class PInvoke
291291
{
292-
#if UNITY_IOS || UNITY_TVOS
292+
#if UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS
293293
private const string DllName = "__Internal";
294294
#elif UNITY_STANDALONE_OSX
295295
private const string DllName = "MacOSAppleAuthManager";

AppleAuth/Editor/ProjectCapabilityManagerExtension.cs

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_IOS || UNITY_TVOS
1+
#if UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS
22

33
using System;
44
using System.Reflection;
@@ -8,69 +8,81 @@ namespace AppleAuth.Editor
88
{
99
public static class ProjectCapabilityManagerExtension
1010
{
11-
private const string EntitlementsArrayKey = "com.apple.developer.applesignin";
12-
private const string DefaultAccessLevel = "Default";
13-
private const string AuthenticationServicesFramework = "AuthenticationServices.framework";
14-
private const BindingFlags NonPublicInstanceBinding = BindingFlags.NonPublic | BindingFlags.Instance;
15-
private const BindingFlags PublicInstanceBinding = BindingFlags.Public | BindingFlags.Instance;
16-
1711
/// <summary>
1812
/// Extension method for ProjectCapabilityManager to add the Sign In With Apple capability in compatibility mode.
1913
/// In particular, adds the AuthenticationServices.framework as an Optional framework, preventing crashes in
2014
/// iOS versions previous to 13.0
2115
/// </summary>
2216
/// <param name="manager">The manager for the main target to use when adding the Sign In With Apple capability.</param>
23-
/// <param name="unityFrameworkTargetGuid">The GUID for the UnityFramework target. If null, it will use the main target GUID.</param>
24-
public static void AddSignInWithAppleWithCompatibility(this ProjectCapabilityManager manager, string unityFrameworkTargetGuid = null)
17+
public static void AddSignInWithAppleWithCompatibility(this ProjectCapabilityManager manager)
2518
{
19+
const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
2620
var managerType = typeof(ProjectCapabilityManager);
2721

28-
var projectField = managerType.GetField("project", NonPublicInstanceBinding);
29-
var targetGuidField = managerType.GetField("m_TargetGuid", NonPublicInstanceBinding);
30-
var entitlementFilePathField = managerType.GetField("m_EntitlementFilePath", NonPublicInstanceBinding);
31-
var getOrCreateEntitlementDocMethod = managerType.GetMethod("GetOrCreateEntitlementDoc", NonPublicInstanceBinding);
32-
33-
// in old unity versions PBXCapabilityType had internal ctor; that was changed to public afterwards - try both
34-
var constructorInfo = GetPBXCapabilityTypeConstructor(PublicInstanceBinding) ??
35-
GetPBXCapabilityTypeConstructor(NonPublicInstanceBinding);
36-
37-
if (projectField == null || targetGuidField == null || entitlementFilePathField == null ||
38-
getOrCreateEntitlementDocMethod == null || constructorInfo == null)
39-
throw new Exception("Can't Add Sign In With Apple programatically in this Unity version");
22+
var projectField = managerType.GetField("project", bindingFlags);
23+
var entitlementFilePathField = managerType.GetField("m_EntitlementFilePath", bindingFlags);
24+
var targetGuidField = managerType.GetField("m_TargetGuid", bindingFlags);
25+
var getOrCreateEntitlementDocMethod = managerType.GetMethod("GetOrCreateEntitlementDoc", bindingFlags);
26+
if (projectField == null ||
27+
entitlementFilePathField == null ||
28+
targetGuidField == null ||
29+
getOrCreateEntitlementDocMethod == null)
30+
throw new Exception("Can't Add Sign In With Apple programatically in this Unity version.");
4031

4132
var entitlementFilePath = entitlementFilePathField.GetValue(manager) as string;
42-
var entitlementDoc = getOrCreateEntitlementDocMethod.Invoke(manager, new object[] { }) as PlistDocument;
33+
var entitlementDoc = (PlistDocument) getOrCreateEntitlementDocMethod.Invoke(manager, new object[] { });
4334
if (entitlementDoc != null)
4435
{
4536
var plistArray = new PlistElementArray();
46-
plistArray.AddString(DefaultAccessLevel);
47-
entitlementDoc.root[EntitlementsArrayKey] = plistArray;
37+
plistArray.AddString("Default");
38+
entitlementDoc.root["com.apple.developer.applesignin"] = plistArray;
4839
}
4940

50-
var project = projectField.GetValue(manager) as PBXProject;
51-
if (project != null)
52-
{
53-
var mainTargetGuid = targetGuidField.GetValue(manager) as string;
54-
var capabilityType = constructorInfo.Invoke(new object[] { "com.apple.developer.applesignin.custom", true, string.Empty, true }) as PBXCapabilityType;
55-
56-
var targetGuidToAddFramework = unityFrameworkTargetGuid;
57-
if (targetGuidToAddFramework == null)
58-
{
59-
targetGuidToAddFramework = mainTargetGuid;
60-
}
61-
62-
project.AddFrameworkToProject(targetGuidToAddFramework, AuthenticationServicesFramework, true);
63-
project.AddCapability(mainTargetGuid, capabilityType, entitlementFilePath, false);
64-
}
41+
var project = (PBXProject) projectField.GetValue(manager);
42+
var emptyCapability = GetEmptyCapabilityWithReflection();
43+
44+
var mainTargetGuid = (string)targetGuidField.GetValue(manager);
45+
#if UNITY_2019_3_OR_NEWER
46+
var frameworkTargetGuid = project.GetUnityFrameworkTargetGuid();
47+
#else
48+
var frameworkTargetGuid = mainTargetGuid;
49+
#endif
50+
51+
project.AddFrameworkToProject(frameworkTargetGuid, "AuthenticationServices.framework", true);
52+
project.AddCapability(mainTargetGuid, emptyCapability, entitlementFilePath);
6553
}
6654

67-
private static ConstructorInfo GetPBXCapabilityTypeConstructor(BindingFlags flags)
55+
private static PBXCapabilityType GetEmptyCapabilityWithReflection()
6856
{
69-
return typeof(PBXCapabilityType).GetConstructor(
70-
flags,
71-
null,
72-
new[] {typeof(string), typeof(bool), typeof(string), typeof(bool)},
73-
null);
57+
// For Unity version >= 6000.0.23f1
58+
var constructorInfo = typeof(PBXCapabilityType)
59+
.GetConstructor(
60+
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
61+
null,
62+
new[] {typeof(bool), typeof(string), typeof(bool)},
63+
null);
64+
65+
if (constructorInfo != null)
66+
{
67+
return (PBXCapabilityType) constructorInfo
68+
.Invoke(new object[] {true, string.Empty, true});
69+
}
70+
71+
// For Unity version < 6000.0.23f1
72+
constructorInfo = typeof(PBXCapabilityType)
73+
.GetConstructor(
74+
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
75+
null,
76+
new[] {typeof(string), typeof(bool), typeof(string), typeof(bool)},
77+
null);
78+
79+
if (constructorInfo != null)
80+
{
81+
return (PBXCapabilityType) constructorInfo
82+
.Invoke(new object[] {"com.lupidan.apple-signin-unity.empty", true, string.Empty, true});
83+
}
84+
85+
throw new Exception("Can't create empty capability in this Unity version.");
7486
}
7587
}
7688
}

AppleAuth/Extensions/PersonNameExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if ((UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX) && !UNITY_EDITOR)
1+
#if ((UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS || UNITY_STANDALONE_OSX) && !UNITY_EDITOR)
22
#define NATIVE_PERSON_NAME_COMPONENTS_AVAILABLE
33
#endif
44

@@ -77,7 +77,7 @@ private static void TryAddKeyValue(string format, string key, string value, Syst
7777

7878
private static class PInvoke
7979
{
80-
#if UNITY_IOS || UNITY_TVOS
80+
#if UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS
8181
private const string DllName = "__Internal";
8282
#elif UNITY_STANDALONE_OSX
8383
private const string DllName = "MacOSAppleAuthManager";

AppleAuth/Native/iOS/AppleAuthManager.h.meta

Lines changed: 4 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AppleAuth/Native/iOS/AppleAuthManager.m

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
#pragma mark - AppleAuthManager Implementation
2929

30-
// IOS/TVOS 13.0 | MACOS 10.15
31-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
30+
// IOS/TVOS 13.0 | MACOS 10.15 | VISIONOS 1.0
31+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 || __VISION_OS_VERSION_MAX_ALLOWED >= 10000
3232
#define AUTHENTICATION_SERVICES_AVAILABLE true
3333
#import <AuthenticationServices/AuthenticationServices.h>
3434
#endif
@@ -45,7 +45,7 @@ - (void) sendsLoginResponseInternalErrorWithCode:(NSInteger)code andMessage:(NSS
4545
@end
4646

4747
#if AUTHENTICATION_SERVICES_AVAILABLE
48-
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0))
48+
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
4949
@interface AppleAuthManager () <ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding>
5050
@property (nonatomic, strong) ASAuthorizationAppleIDProvider *appleIdProvider;
5151
@property (nonatomic, strong) ASAuthorizationPasswordProvider *passwordProvider;
@@ -74,7 +74,7 @@ - (instancetype) init
7474
if (self)
7575
{
7676
#if AUTHENTICATION_SERVICES_AVAILABLE
77-
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, *))
77+
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, visionOS 1.0, *))
7878
{
7979
_appleIdProvider = [[ASAuthorizationAppleIDProvider alloc] init];
8080
_passwordProvider = [[ASAuthorizationPasswordProvider alloc] init];
@@ -90,7 +90,7 @@ - (instancetype) init
9090
- (void) quickLogin:(uint)requestId withNonce:(NSString *)nonce andState:(NSString *)state
9191
{
9292
#if AUTHENTICATION_SERVICES_AVAILABLE
93-
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, *))
93+
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, visionOS 1.0, *))
9494
{
9595
ASAuthorizationAppleIDRequest *appleIDRequest = [[self appleIdProvider] createRequest];
9696
[appleIDRequest setNonce:nonce];
@@ -117,7 +117,7 @@ - (void) quickLogin:(uint)requestId withNonce:(NSString *)nonce andState:(NSStri
117117
- (void) loginWithAppleId:(uint)requestId withOptions:(AppleAuthManagerLoginOptions)options nonce:(NSString *)nonce andState:(NSString *)state
118118
{
119119
#if AUTHENTICATION_SERVICES_AVAILABLE
120-
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, *))
120+
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, visionOS 1.0, *))
121121
{
122122
ASAuthorizationAppleIDRequest *request = [[self appleIdProvider] createRequest];
123123
NSMutableArray *scopes = [NSMutableArray array];
@@ -152,7 +152,7 @@ - (void) loginWithAppleId:(uint)requestId withOptions:(AppleAuthManagerLoginOpti
152152
- (void) getCredentialStateForUser:(NSString *)userId withRequestId:(uint)requestId
153153
{
154154
#if AUTHENTICATION_SERVICES_AVAILABLE
155-
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, *))
155+
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, visionOS 1.0, *))
156156
{
157157
[[self appleIdProvider] getCredentialStateForUserID:userId completion:^(ASAuthorizationAppleIDProviderCredentialState credentialState, NSError * _Nullable error) {
158158
NSNumber *credentialStateNumber = nil;
@@ -185,7 +185,7 @@ - (void) getCredentialStateForUser:(NSString *)userId withRequestId:(uint)reques
185185
- (void) registerCredentialsRevokedCallbackForRequestId:(uint)requestId
186186
{
187187
#if AUTHENTICATION_SERVICES_AVAILABLE
188-
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, *))
188+
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, visionOS 1.0, *))
189189
{
190190
if ([self credentialsRevokedObserver])
191191
{
@@ -265,7 +265,7 @@ - (void) sendsLoginResponseInternalErrorWithCode:(NSInteger)code andMessage:(NSS
265265
#if AUTHENTICATION_SERVICES_AVAILABLE
266266

267267
- (void) performAuthorizationRequestsForController:(ASAuthorizationController *)authorizationController withRequestId:(uint)requestId
268-
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0))
268+
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
269269
{
270270
NSValue *authControllerAsKey = [NSValue valueWithNonretainedObject:authorizationController];
271271
[[self authorizationsInProgress] setObject:@(requestId) forKey:authControllerAsKey];
@@ -278,7 +278,7 @@ - (void) performAuthorizationRequestsForController:(ASAuthorizationController *)
278278
#pragma mark ASAuthorizationControllerDelegate protocol implementation
279279

280280
- (void) authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization
281-
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0))
281+
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
282282
{
283283
NSValue *authControllerAsKey = [NSValue valueWithNonretainedObject:controller];
284284
NSNumber *requestIdNumber = [[self authorizationsInProgress] objectForKey:authControllerAsKey];
@@ -306,7 +306,7 @@ - (void) authorizationController:(ASAuthorizationController *)controller didComp
306306
}
307307

308308
- (void) authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error
309-
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0))
309+
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
310310
{
311311
NSValue *authControllerAsKey = [NSValue valueWithNonretainedObject:controller];
312312
NSNumber *requestIdNumber = [[self authorizationsInProgress] objectForKey:authControllerAsKey];
@@ -326,9 +326,10 @@ - (void) authorizationController:(ASAuthorizationController *)controller didComp
326326
#pragma mark ASAuthorizationControllerPresentationContextProviding protocol implementation
327327

328328
- (ASPresentationAnchor) presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller
329-
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0))
329+
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
330330
{
331-
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000
331+
332+
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 || __VISION_OS_VERSION_MAX_ALLOWED >= 10000
332333
return [[[UIApplication sharedApplication] delegate] window];
333334
#elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
334335
return [[NSApplication sharedApplication] mainWindow];
@@ -343,9 +344,9 @@ - (ASPresentationAnchor) presentationAnchorForAuthorizationController:(ASAuthori
343344

344345
#pragma mark - Native C Calls
345346

346-
bool AppleAuth_IsCurrentPlatformSupported()
347+
bool AppleAuth_IsCurrentPlatformSupported(void)
347348
{
348-
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, *))
349+
if (@available(iOS 13.0, tvOS 13.0, macOS 10.15, visionOS 1.0, *))
349350
{
350351
return true;
351352
}

0 commit comments

Comments
 (0)