This commit is contained in:
2025-11-13 19:07:59 +08:00
parent 5ec950cc61
commit 50163d02a7
9 changed files with 378 additions and 88 deletions

View File

@@ -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]; };