Safari服务崩溃[SFAuthenticationViewController dismissViewControllerAnimated:completion:]

时间:2017-10-29 16:10:26

标签: ios crash ios11

我的应用中经常发生崩溃。 iOS系统的崩溃似乎只发生在最新的iOS 11中。

这是崩溃

Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x18439d7ec objc_object::release() + 8
1  SafariServices                 0x1995d471c __75-[SFAuthenticationViewController dismissViewControllerAnimated:completion:]_block_invoke + 32
2  UIKit                          0x18e5bf030 -[UIPresentationController transitionDidFinish:] + 1320
3  UIKit                          0x18e79e760 -[_UICurrentContextPresentationController transitionDidFinish:] + 44
4  UIKit                          0x18e5c2a20 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 188
5  UIKit                          0x18e38e9d8 -[_UIViewControllerTransitionContext completeTransition:] + 116
6  UIKit                          0x18e38e7c8 -[UITransitionView notifyDidCompleteTransition:] + 252
7  UIKit                          0x18e38e260 -[UITransitionView _didCompleteTransition:] + 1128
8  UIKit                          0x18e38dde4 -[UITransitionView _transitionDidStop:finished:] + 120
9  UIKit                          0x18e2b370c -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 312
10 UIKit                          0x18e2b3418 -[UIViewAnimationState animationDidStop:finished:] + 296
11 UIKit                          0x18e2b34b8 -[UIViewAnimationState animationDidStop:finished:] + 456
12 QuartzCore                     0x188e57d6c CA::Layer::run_animation_callbacks(void*) + 284
13 libdispatch.dylib              0x1847f1048 _dispatch_client_callout + 16
14 libdispatch.dylib              0x1847fdb74 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1016
15 CoreFoundation                 0x184e13f20 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
16 CoreFoundation                 0x184e11afc __CFRunLoopRun + 2012
17 CoreFoundation                 0x184d322d8 CFRunLoopRunSpecific + 436
18 GraphicsServices               0x186bc3f84 GSEventRunModal + 100
19 UIKit                          0x18e2df880 UIApplicationMain + 208
20 Jaumo                          0x1005674b4 main (main.m:20)
21 libdyld.dylib                  0x18485656c start + 4

不确定这次崩溃是什么。有人可以帮忙解决这个问题吗?

3 个答案:

答案 0 :(得分:3)

在我们更新到最新的Facebook SDK(从相当旧的版本4.11到4.27.1)后,我们遇到了同样的问题。实际上我们有一些来自applicationDidBecomeActive事件的呼叫触发了Facebook登录(因此打开SFAuthenticationSession会打开SFAuthenticationViewController提示,要求用户继续通过Facebook或其他第三方进行身份验证)。用户点击“继续”后再次触发applicationDidBecomeActive事件。这导致无限循环启动新SFAuthenticaionSessions导致崩溃。所以我们决定不从这个事件中调用Facebook登录。总结一下如何避免这种崩溃:你必须确保只在同一时间调用Facebook登录(或SFAuthenticationSession start()方法)。

答案 1 :(得分:2)

正如@ZoltánHomoki和@Jelly所说,我们应该只召唤logInWithReadPermissions一次。

为此目的,一个常见的实现(之前还可以)是在appDelegate中设置一个标志,如:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    if ([[url.scheme substringToIndex:2] isEqualToString:@"fb"]) {
        _fromFbConnect = YES; // <- This flag
        returnValue = [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    // Manage app deep links here
}

然后使用它来防止多次调用Facebook登录:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [FBSDKAppEvents activateApp];

    if (_fromFbConnect == NO) { // <- Always `YES` on iOS11 with FB SDK 4.27
        // Refresh the facebook token
        if ([FBSDKAccessToken currentAccessToken] != nil) {
            [[FBSDKLoginManager new] logInWithReadPermissions: // ...
        }
        _fromFbConnect = NO;
    }
}

问题是在iOS11上FBSDKLoginKit&gt; = 4.27 application:openURL:sourceApplication:annotation:未调用(也不是application:openURL:option),因此未设置该标志。这会创建对登录的多次调用(当用户关闭第一个弹出窗口时调用applicationDidBecomeActive

我找到的解决方案是在调用FBSDKLoginManager之前设置一个标志,并停止任何其他调用,直到该过程完成。

@property (assign, nonatomic) BOOL fbRequesting;

// ...

if(_fbRequesting == YES) {
    NSLog(@"Facebook login already in progress");
    return;
}

if ([FBSDKAccessToken currentAccessToken] != nil) {
    return;
}

_fbRequesting = YES;
[FBSDKProfile enableUpdatesOnAccessTokenChange:YES];

NSLog(@"Logging in to Facebook...");

@weakify(self);
[[FBSDKLoginManager new] logInWithReadPermissions:... fromViewController:... handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
    @strongify(self);

    // Handle login

    _fbRequesting = NO;
    })
];

这似乎适用于FBSDKLoginKit的版本4.22到4.28。

答案 2 :(得分:1)

只是在FB SDK 4.31.1中遇到了崩溃,这就是我解决的方法。

就我而言,只有当我尝试开始登录FB且已经开始FB登录(屏幕上显示Safari Web视图)时,才会发生崩溃。

所以我只检查:

UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
       topController = topController.presentedViewController;
    }

if ([topController isKindOfClass:[MyViewController class]])
{
     // If that's my view controller, we can start FB Login
}