1
This commit is contained in:
@@ -26,6 +26,11 @@ static NSString * const kKBAppleUserIdentifierKey = @"com.company.keyboard.apple
|
||||
}
|
||||
|
||||
- (void)signInFromViewController:(UIViewController *)presenting completion:(KBAppleSignInCompletion)completion {
|
||||
if (!NSThread.isMainThread) {
|
||||
// 确保在主线程发起,否则可能得到 Unknown(1000)
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [self signInFromViewController:presenting completion:completion]; });
|
||||
return;
|
||||
}
|
||||
if (@available(iOS 13.0, *)) {
|
||||
self.presentingVC = presenting;
|
||||
self.completion = completion;
|
||||
@@ -110,7 +115,21 @@ static NSString * const kKBAppleUserIdentifierKey = @"com.company.keyboard.apple
|
||||
#pragma mark - 授权界面展示锚点 (ASAuthorizationControllerPresentationContextProviding)
|
||||
|
||||
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)) {
|
||||
return self.presentingVC.view.window ?: UIApplication.sharedApplication.keyWindow;
|
||||
// 优先用传入 VC 的 window
|
||||
UIWindow *win = self.presentingVC.view.window;
|
||||
if (win) return win;
|
||||
// iOS13+ 从前台激活的 scene 中取 keyWindow
|
||||
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
|
||||
if (scene.activationState == UISceneActivationStateForegroundActive && [scene isKindOfClass:[UIWindowScene class]]) {
|
||||
UIWindowScene *ws = (UIWindowScene *)scene;
|
||||
for (UIWindow *w in ws.windows) { if (w.isKeyWindow) return w; }
|
||||
if (ws.windows.firstObject) return ws.windows.firstObject;
|
||||
}
|
||||
}
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
return UIApplication.sharedApplication.keyWindow ?: UIApplication.sharedApplication.windows.firstObject;
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
#pragma mark - Keychain 工具
|
||||
|
||||
Reference in New Issue
Block a user