ios登录测试
This commit is contained in:
parent
3a35ffcbc5
commit
bdb9e6c833
@ -50,7 +50,7 @@ API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
|||||||
@property (nonatomic, strong) ASAuthorizationAppleIDProvider *appleIdProvider;
|
@property (nonatomic, strong) ASAuthorizationAppleIDProvider *appleIdProvider;
|
||||||
@property (nonatomic, strong) ASAuthorizationPasswordProvider *passwordProvider;
|
@property (nonatomic, strong) ASAuthorizationPasswordProvider *passwordProvider;
|
||||||
@property (nonatomic, strong) NSObject *credentialsRevokedObserver;
|
@property (nonatomic, strong) NSObject *credentialsRevokedObserver;
|
||||||
@property (nonatomic, strong) NSMutableDictionary<NSValue *, NSNumber *> *authorizationsInProgress;
|
@property (nonatomic, strong) NSMapTable<ASAuthorizationController *, NSNumber *> *authorizationsInProgress;
|
||||||
@end
|
@end
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
|||||||
{
|
{
|
||||||
_appleIdProvider = [[ASAuthorizationAppleIDProvider alloc] init];
|
_appleIdProvider = [[ASAuthorizationAppleIDProvider alloc] init];
|
||||||
_passwordProvider = [[ASAuthorizationPasswordProvider alloc] init];
|
_passwordProvider = [[ASAuthorizationPasswordProvider alloc] init];
|
||||||
_authorizationsInProgress = [NSMutableDictionary dictionary];
|
_authorizationsInProgress = [NSMapTable mapTableWithKeyOptions:NSPointerFunctionsStrongMemory valueOptions:NSPointerFunctionsStrongMemory];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -267,8 +267,8 @@ API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
|||||||
- (void) performAuthorizationRequestsForController:(ASAuthorizationController *)authorizationController withRequestId:(uint)requestId
|
- (void) performAuthorizationRequestsForController:(ASAuthorizationController *)authorizationController withRequestId:(uint)requestId
|
||||||
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
||||||
{
|
{
|
||||||
NSValue *authControllerAsKey = [NSValue valueWithNonretainedObject:authorizationController];
|
// 使用强引用 NSMapTable 保存 ASAuthorizationController,避免其被提前释放导致 delegate 回调不触发
|
||||||
[[self authorizationsInProgress] setObject:@(requestId) forKey:authControllerAsKey];
|
[[self authorizationsInProgress] setObject:@(requestId) forKey:authorizationController];
|
||||||
|
|
||||||
[authorizationController setDelegate:self];
|
[authorizationController setDelegate:self];
|
||||||
[authorizationController setPresentationContextProvider:self];
|
[authorizationController setPresentationContextProvider:self];
|
||||||
@ -280,8 +280,7 @@ API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
|||||||
- (void) authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization
|
- (void) authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization
|
||||||
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
||||||
{
|
{
|
||||||
NSValue *authControllerAsKey = [NSValue valueWithNonretainedObject:controller];
|
NSNumber *requestIdNumber = [[self authorizationsInProgress] objectForKey:controller];
|
||||||
NSNumber *requestIdNumber = [[self authorizationsInProgress] objectForKey:authControllerAsKey];
|
|
||||||
if (requestIdNumber)
|
if (requestIdNumber)
|
||||||
{
|
{
|
||||||
NSDictionary *appleIdCredentialDictionary = nil;
|
NSDictionary *appleIdCredentialDictionary = nil;
|
||||||
@ -301,15 +300,14 @@ API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
|||||||
|
|
||||||
[self sendNativeMessageForDictionary:responseDictionary forRequestId:[requestIdNumber unsignedIntValue]];
|
[self sendNativeMessageForDictionary:responseDictionary forRequestId:[requestIdNumber unsignedIntValue]];
|
||||||
|
|
||||||
[[self authorizationsInProgress] removeObjectForKey:authControllerAsKey];
|
[[self authorizationsInProgress] removeObjectForKey:controller];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error
|
- (void) authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error
|
||||||
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
||||||
{
|
{
|
||||||
NSValue *authControllerAsKey = [NSValue valueWithNonretainedObject:controller];
|
NSNumber *requestIdNumber = [[self authorizationsInProgress] objectForKey:controller];
|
||||||
NSNumber *requestIdNumber = [[self authorizationsInProgress] objectForKey:authControllerAsKey];
|
|
||||||
if (requestIdNumber)
|
if (requestIdNumber)
|
||||||
{
|
{
|
||||||
NSDictionary *errorDictionary = [AppleAuthSerializer dictionaryForNSError:error];
|
NSDictionary *errorDictionary = [AppleAuthSerializer dictionaryForNSError:error];
|
||||||
@ -319,7 +317,7 @@ API_AVAILABLE(ios(13.0), macos(10.15), tvos(13.0), watchos(6.0), visionos(1.0))
|
|||||||
|
|
||||||
[self sendNativeMessageForDictionary:responseDictionary forRequestId:[requestIdNumber unsignedIntValue]];
|
[self sendNativeMessageForDictionary:responseDictionary forRequestId:[requestIdNumber unsignedIntValue]];
|
||||||
|
|
||||||
[[self authorizationsInProgress] removeObjectForKey:authControllerAsKey];
|
[[self authorizationsInProgress] removeObjectForKey:controller];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -122,9 +122,12 @@ namespace Kill.Managers
|
|||||||
loginArgs,
|
loginArgs,
|
||||||
credential =>
|
credential =>
|
||||||
{
|
{
|
||||||
|
Debug.Log($"[AppleAuth] 登录成功回调触发, credential类型: {credential?.GetType().Name}");
|
||||||
var appleIdCredential = credential as IAppleIDCredential;
|
var appleIdCredential = credential as IAppleIDCredential;
|
||||||
if (appleIdCredential == null)
|
if (appleIdCredential == null)
|
||||||
{
|
{
|
||||||
|
var passwordCredential = credential as IPasswordCredential;
|
||||||
|
Debug.LogWarning($"[AppleAuth] credential 不是 AppleIDCredential, 实际类型: {credential?.GetType().Name}, PasswordCredential: {passwordCredential != null}");
|
||||||
MainThread.Enqueue(() => onError?.Invoke("未获取到 Apple ID 凭证"));
|
MainThread.Enqueue(() => onError?.Invoke("未获取到 Apple ID 凭证"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -132,6 +135,8 @@ namespace Kill.Managers
|
|||||||
var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken);
|
var identityToken = Encoding.UTF8.GetString(appleIdCredential.IdentityToken);
|
||||||
var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode);
|
var authorizationCode = Encoding.UTF8.GetString(appleIdCredential.AuthorizationCode);
|
||||||
|
|
||||||
|
Debug.Log($"[AppleAuth] identityToken长度: {identityToken?.Length}, authorizationCode长度: {authorizationCode?.Length}");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(identityToken))
|
if (string.IsNullOrEmpty(identityToken))
|
||||||
{
|
{
|
||||||
MainThread.Enqueue(() => onError?.Invoke("Apple identity token 为空"));
|
MainThread.Enqueue(() => onError?.Invoke("Apple identity token 为空"));
|
||||||
@ -142,6 +147,7 @@ namespace Kill.Managers
|
|||||||
},
|
},
|
||||||
error =>
|
error =>
|
||||||
{
|
{
|
||||||
|
Debug.LogError($"[AppleAuth] 登录失败回调触发: {error?.LocalizedDescription}");
|
||||||
MainThread.Enqueue(() => onError?.Invoke($"Apple 登录失败: {error.LocalizedDescription}"));
|
MainThread.Enqueue(() => onError?.Invoke($"Apple 登录失败: {error.LocalizedDescription}"));
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user