3
This commit is contained in:
@@ -135,52 +135,14 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK
|
||||
__weak typeof(pop) weakPop = pop;
|
||||
view.appleLoginHandler = ^{
|
||||
[weakPop dismiss];
|
||||
[[AppleSignInManager shared] signInFromViewController:KB_CURRENT_NAV completion:^(ASAuthorizationAppleIDCredential * _Nullable credential, NSError * _Nullable error) {
|
||||
NSLog(@"=====");
|
||||
// 成功回调:仅处理 AppleID 凭证
|
||||
if (![credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
|
||||
return;
|
||||
}
|
||||
ASAuthorizationAppleIDCredential *cred = (ASAuthorizationAppleIDCredential *)credential;
|
||||
|
||||
// identityToken 与 authorizationCode 需要发给后端校验
|
||||
NSString *tokenString = nil;
|
||||
if (cred.identityToken) {
|
||||
tokenString = [[NSString alloc] initWithData:cred.identityToken encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
NSString *authorizationCodeString = nil;
|
||||
if (cred.authorizationCode) {
|
||||
authorizationCodeString = [[NSString alloc] initWithData:cred.authorizationCode encoding:NSUTF8StringEncoding];
|
||||
}
|
||||
|
||||
// fullName 仅在首次授权时可能返回
|
||||
NSString *fullName = nil;
|
||||
if (cred.fullName.givenName.length || cred.fullName.familyName.length) {
|
||||
NSString *given = cred.fullName.givenName ?: @"";
|
||||
NSString *family = cred.fullName.familyName ?: @"";
|
||||
fullName = [[NSString stringWithFormat:@"%@ %@", given, family] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||
}
|
||||
|
||||
// 保存 user 标识,后续可以查询撤销状态或和账号体系绑定(生产建议存钥匙串)
|
||||
NSString *userID = cred.user;
|
||||
// [self _persistAppleUserIdentifier:userID];
|
||||
|
||||
// NSDictionary *params = @{
|
||||
// @"userID": userID ?: @"",
|
||||
// @"accessCode": authorizationCodeString ?: @"",
|
||||
// // 可选字段:若后端不接受,请删除下列键
|
||||
// @"identityToken": tokenString ?: @"",
|
||||
// @"fullName": fullName ?: @"",
|
||||
// @"state": cred.state ?: @""
|
||||
// };
|
||||
NSDictionary *params = @{
|
||||
@"code": tokenString ?: @"",
|
||||
};
|
||||
[[KBNetworkManager shared] POST:API_APPLE_LOGIN jsonBody:params headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
NSLog(@"=====");
|
||||
}];
|
||||
|
||||
NSLog(@"====");
|
||||
// 交给 VM 统一处理 Apple 登录 + 服务端登录
|
||||
[[KBLoginVM shared] signInWithAppleFromViewController:KB_CURRENT_NAV completion:^(BOOL success, NSError * _Nullable error) {
|
||||
if (success) {
|
||||
[KBHUD showInfo:@"登录成功"];
|
||||
} else {
|
||||
NSString *msg = error.localizedDescription ?: @"登录失败";
|
||||
[KBHUD showInfo:msg];
|
||||
}
|
||||
}];
|
||||
};
|
||||
view.closeHandler = ^{ [weakPop dismiss]; };
|
||||
|
||||
Reference in New Issue
Block a user