1
This commit is contained in:
@@ -110,10 +110,10 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK
|
||||
|
||||
- (void)kb_presentLoginSheetIfNeeded {
|
||||
// 已登录则不提示
|
||||
BOOL loggedIn = ([AppleSignInManager shared].storedUserIdentifier.length > 0);
|
||||
if (loggedIn) return;
|
||||
UIViewController *top = [UIViewController kb_topMostViewController];
|
||||
if (!top) return;
|
||||
// BOOL loggedIn = ([AppleSignInManager shared].storedUserIdentifier.length > 0);
|
||||
// if (loggedIn) return;
|
||||
// UIViewController *top = [UIViewController kb_topMostViewController];
|
||||
// if (!top) return;
|
||||
// [KBLoginSheetViewController presentIfNeededFrom:top];
|
||||
[self goLogin];
|
||||
|
||||
@@ -137,6 +137,57 @@ static NSString * const kKBKeyboardExtensionBundleId = @"com.loveKey.nyx.CustomK
|
||||
[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:@"/user/appleLogin" parameters:params headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
|
||||
//
|
||||
// } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
//
|
||||
// } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
//
|
||||
// }];
|
||||
[[KBNetworkManager shared] POST:@"/user/appleLogin" jsonBody:params headers:nil completion:^(id _Nullable jsonOrData, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
NSLog(@"=====");
|
||||
}];
|
||||
|
||||
NSLog(@"====");
|
||||
}];
|
||||
};
|
||||
view.closeHandler = ^{ [weakPop dismiss]; };
|
||||
|
||||
Reference in New Issue
Block a user