Skip to content

Commit dba7173

Browse files
authored
Merge pull request #36 from lupidan/canary
v1.2.0 Release
2 parents 052252e + b43986c commit dba7173

70 files changed

Lines changed: 3061 additions & 206 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AppleAuth/AppleAuthManager.cs

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

@@ -21,7 +21,7 @@ public static bool IsCurrentPlatformSupported
2121
get
2222
{
2323
#if APPLE_AUTH_MANAGER_NATIVE_IMPLEMENTATION_AVAILABLE
24-
return PInvoke.AppleAuth_IOS_IsCurrentPlatformSupported();
24+
return PInvoke.AppleAuth_IsCurrentPlatformSupported();
2525
#else
2626
return false;
2727
#endif
@@ -60,7 +60,7 @@ public void QuickLogin(
6060
successCallback(response.AppleIDCredential);
6161
});
6262

63-
PInvoke.AppleAuth_IOS_QuickLogin(requestId, nonce);
63+
PInvoke.AppleAuth_QuickLogin(requestId, nonce);
6464
#else
6565
throw new Exception("AppleAuthManager is not supported in this platform");
6666
#endif
@@ -90,7 +90,7 @@ public void LoginWithAppleId(
9090
successCallback(response.AppleIDCredential);
9191
});
9292

93-
PInvoke.AppleAuth_IOS_LoginWithAppleId(requestId, (int)loginOptions, nonce);
93+
PInvoke.AppleAuth_LoginWithAppleId(requestId, (int)loginOptions, nonce);
9494
#else
9595
throw new Exception("AppleAuthManager is not supported in this platform");
9696
#endif
@@ -113,7 +113,7 @@ public void GetCredentialState(
113113
successCallback(response.CredentialState);
114114
});
115115

116-
PInvoke.AppleAuth_IOS_GetCredentialState(requestId, userId);
116+
PInvoke.AppleAuth_GetCredentialState(requestId, userId);
117117
#else
118118
throw new Exception("AppleAuthManager is not supported in this platform");
119119
#endif
@@ -168,7 +168,7 @@ public static event Action<string> NativeCredentialsRevoked
168168
if (_nativeCredentialsRevoked == null)
169169
{
170170
_credentialsRevokedCallbackId = AddMessageCallback(false, payload => _nativeCredentialsRevoked.Invoke(payload));
171-
PInvoke.AppleAuth_IOS_RegisterCredentialsRevokedCallbackId(_credentialsRevokedCallbackId);
171+
PInvoke.AppleAuth_RegisterCredentialsRevokedCallbackId(_credentialsRevokedCallbackId);
172172
}
173173

174174
_nativeCredentialsRevoked += value;
@@ -185,7 +185,7 @@ public static event Action<string> NativeCredentialsRevoked
185185
{
186186
RemoveMessageCallback(_credentialsRevokedCallbackId);
187187
_credentialsRevokedCallbackId = 0U;
188-
PInvoke.AppleAuth_IOS_RegisterCredentialsRevokedCallbackId(0U);
188+
PInvoke.AppleAuth_RegisterCredentialsRevokedCallbackId(0U);
189189
}
190190
}
191191
}
@@ -226,7 +226,7 @@ public static uint AddMessageCallback(bool isSingleUse, Action<string> messageCa
226226
{
227227
if (!_initialized)
228228
{
229-
PInvoke.AppleAuth_IOS_SetupNativeMessageHandlerCallback(PInvoke.NativeMessageHandlerCallback);
229+
PInvoke.AppleAuth_SetupNativeMessageHandlerCallback(PInvoke.NativeMessageHandlerCallback);
230230
_initialized = true;
231231
}
232232

@@ -277,6 +277,12 @@ public Entry(bool isSingleUseCallback, Action<string> messageCallback)
277277

278278
private static class PInvoke
279279
{
280+
#if UNITY_IOS || UNITY_TVOS
281+
private const string DllName = "__Internal";
282+
#elif UNITY_STANDALONE_OSX
283+
private const string DllName = "MacOSAppleAuthManager";
284+
#endif
285+
280286
public delegate void NativeMessageHandlerCallbackDelegate(uint requestId, string payload);
281287

282288
[AOT.MonoPInvokeCallback(typeof(NativeMessageHandlerCallbackDelegate))]
@@ -294,23 +300,23 @@ public static void NativeMessageHandlerCallback(uint requestId, string payload)
294300
}
295301
}
296302

297-
[System.Runtime.InteropServices.DllImport("__Internal")]
298-
public static extern bool AppleAuth_IOS_IsCurrentPlatformSupported();
303+
[System.Runtime.InteropServices.DllImport(DllName)]
304+
public static extern bool AppleAuth_IsCurrentPlatformSupported();
299305

300-
[System.Runtime.InteropServices.DllImport("__Internal")]
301-
public static extern void AppleAuth_IOS_SetupNativeMessageHandlerCallback(NativeMessageHandlerCallbackDelegate callback);
306+
[System.Runtime.InteropServices.DllImport(DllName)]
307+
public static extern void AppleAuth_SetupNativeMessageHandlerCallback(NativeMessageHandlerCallbackDelegate callback);
302308

303-
[System.Runtime.InteropServices.DllImport("__Internal")]
304-
public static extern void AppleAuth_IOS_GetCredentialState(uint requestId, string userId);
309+
[System.Runtime.InteropServices.DllImport(DllName)]
310+
public static extern void AppleAuth_GetCredentialState(uint requestId, string userId);
305311

306-
[System.Runtime.InteropServices.DllImport("__Internal")]
307-
public static extern void AppleAuth_IOS_LoginWithAppleId(uint requestId, int loginOptions, string nonceCStr);
312+
[System.Runtime.InteropServices.DllImport(DllName)]
313+
public static extern void AppleAuth_LoginWithAppleId(uint requestId, int loginOptions, string nonceCStr);
308314

309-
[System.Runtime.InteropServices.DllImport("__Internal")]
310-
public static extern void AppleAuth_IOS_QuickLogin(uint requestId, string nonceCStr);
315+
[System.Runtime.InteropServices.DllImport(DllName)]
316+
public static extern void AppleAuth_QuickLogin(uint requestId, string nonceCStr);
311317

312-
[System.Runtime.InteropServices.DllImport("__Internal")]
313-
public static extern void AppleAuth_IOS_RegisterCredentialsRevokedCallbackId(uint callbackId);
318+
[System.Runtime.InteropServices.DllImport(DllName)]
319+
public static extern void AppleAuth_RegisterCredentialsRevokedCallbackId(uint callbackId);
314320
}
315321
#endif
316322
}

AppleAuth/Editor/ProjectCapabilityManagerExtension.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ public static class ProjectCapabilityManagerExtension
1313
private const string AuthenticationServicesFramework = "AuthenticationServices.framework";
1414
private const BindingFlags NonPublicInstanceBinding = BindingFlags.NonPublic | BindingFlags.Instance;
1515

16-
public static void AddSignInWithApple(this ProjectCapabilityManager manager)
16+
/// <summary>
17+
/// Extension method for ProjectCapabilityManager to add the Sign In With Apple capability in compatibility mode.
18+
/// In particular, adds the AuthenticationServices.framework as an Optional framework, preventing crashes in
19+
/// iOS versions previous to 13.0
20+
/// </summary>
21+
/// <param name="manager">The manager for the main target to use when adding the Sign In With Apple capability.</param>
22+
/// <param name="unityFrameworkTargetGuid">The GUID for the UnityFramework target. If null, it will use the main target GUID.</param>
23+
public static void AddSignInWithAppleWithCompatibility(this ProjectCapabilityManager manager, string unityFrameworkTargetGuid = null)
1724
{
1825
var managerType = typeof(ProjectCapabilityManager);
1926
var capabilityTypeType = typeof(PBXCapabilityType);
@@ -44,10 +51,12 @@ public static void AddSignInWithApple(this ProjectCapabilityManager manager)
4451
var project = projectField.GetValue(manager) as PBXProject;
4552
if (project != null)
4653
{
47-
var targetGuid = targetGuidField.GetValue(manager) as string;
48-
var capabilityType = constructorInfo.Invoke(new object[] { "com.apple.signin", true, AuthenticationServicesFramework, true }) as PBXCapabilityType;
49-
project.AddCapability(targetGuid, capabilityType, entitlementFilePath, false);
50-
project.AddFrameworkToProject(targetGuid, AuthenticationServicesFramework, true);
54+
var mainTargetGuid = targetGuidField.GetValue(manager) as string;
55+
var capabilityType = constructorInfo.Invoke(new object[] { "com.apple.developer.applesignin.custom", true, string.Empty, true }) as PBXCapabilityType;
56+
57+
var targetGuidToAddFramework = unityFrameworkTargetGuid ?? mainTargetGuid;
58+
project.AddFrameworkToProject(targetGuidToAddFramework, AuthenticationServicesFramework, true);
59+
project.AddCapability(mainTargetGuid, capabilityType, entitlementFilePath, false);
5160
}
5261
}
5362
}

AppleAuth/Extensions/PersonNameExtensions.cs

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

@@ -16,8 +16,12 @@ public static string ToLocalizedString(
1616
{
1717
#if NATIVE_PERSON_NAME_COMPONENTS_AVAILABLE
1818
var jsonString = JsonStringForPersonName(personName);
19-
return PInvoke.AppleAuth_IOS_GetPersonNameUsingFormatter(jsonString, (int) style, usePhoneticRepresentation);
20-
#else
19+
var localizedString = PInvoke.AppleAuth_GetPersonNameUsingFormatter(jsonString, (int) style, usePhoneticRepresentation);
20+
if (localizedString != null)
21+
{
22+
return localizedString;
23+
}
24+
#endif
2125
var orderedParts = new System.Collections.Generic.List<string>();
2226
if (string.IsNullOrEmpty(personName.NamePrefix))
2327
orderedParts.Add(personName.NamePrefix);
@@ -35,7 +39,6 @@ public static string ToLocalizedString(
3539
orderedParts.Add(personName.NameSuffix);
3640

3741
return string.Join(" ", orderedParts.ToArray());
38-
#endif
3942
}
4043

4144
#if NATIVE_PERSON_NAME_COMPONENTS_AVAILABLE
@@ -74,8 +77,14 @@ private static void TryAddKeyValue(string format, string key, string value, Syst
7477

7578
private static class PInvoke
7679
{
77-
[System.Runtime.InteropServices.DllImport("__Internal")]
78-
public static extern string AppleAuth_IOS_GetPersonNameUsingFormatter(string payload, int style, bool usePhoneticRepresentation);
80+
#if UNITY_IOS || UNITY_TVOS
81+
private const string DllName = "__Internal";
82+
#elif UNITY_STANDALONE_OSX
83+
private const string DllName = "MacOSAppleAuthManager";
84+
#endif
85+
86+
[System.Runtime.InteropServices.DllImport(DllName)]
87+
public static extern string AppleAuth_GetPersonNameUsingFormatter(string payload, int style, bool usePhoneticRepresentation);
7988
}
8089
#endif
8190
}

AppleAuth/IOS/ObjC/PersonNameComponentsFormatting.m

Lines changed: 0 additions & 71 deletions
This file was deleted.

AppleAuth/IOS/NativeMessages/AppleError.cs renamed to AppleAuth/Native/AppleError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System;
33
using UnityEngine;
44

5-
namespace AppleAuth.IOS.NativeMessages
5+
namespace AppleAuth.Native
66
{
77
[Serializable]
88
public class AppleError : IAppleError, ISerializationCallbackReceiver
File renamed without changes.

AppleAuth/IOS/NativeMessages/AppleIDCredential.cs renamed to AppleAuth/Native/AppleIDCredential.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System;
44
using UnityEngine;
55

6-
namespace AppleAuth.IOS.NativeMessages
6+
namespace AppleAuth.Native
77
{
88
[Serializable]
99
public class AppleIDCredential : IAppleIDCredential, ISerializationCallbackReceiver
File renamed without changes.

AppleAuth/IOS/NativeMessages/CredentialStateResponse.cs renamed to AppleAuth/Native/CredentialStateResponse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System;
44
using UnityEngine;
55

6-
namespace AppleAuth.IOS.NativeMessages
6+
namespace AppleAuth.Native
77
{
88
[Serializable]
99
public class CredentialStateResponse : ICredentialStateResponse, ISerializationCallbackReceiver

0 commit comments

Comments
 (0)