This commit is contained in:
2025-11-13 14:11:44 +08:00
parent bc261661ae
commit debbe2777b
28 changed files with 250 additions and 33 deletions

View File

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