插件后 Cordova 视图无响应 returns

Cordova view unresponsive after plugin returns

我正在尝试使 iOS 的 auth0 锁与 cordova 一起使用。它似乎有效,除了我在插件完成后关闭视图时做错了什么。它被解雇了,但我无法再与 cordova 视图进行交互。它变得反应迟钝。

插件代码如下:

@implementation lockPlugin

-(void)init:(CDVInvokedUrlCommand*)command {

    A0Lock *lock = [A0Lock sharedLock];

    A0LockViewController *controller = [lock newLockViewController];
    controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) {

        CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
                                                messageAsDictionary:@{
                                                                      @"idToken":token.idToken,
                                                                      @"refreshToken":token.refreshToken,
                                                                      @"tokenType":token.tokenType,
                                                                      @"accessToken":token.accessToken,
                                                                      @"email":profile.email
                                                                      }];

        [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];

        [self.viewController dismissViewControllerAnimated:YES completion:nil];

    };
    [lock presentLockController:controller fromController:self.viewController];

}
@end

我不得不承认您的代码看起来不错,而且我在 Google 上找不到任何问题。我确实找到了一些关于竞争条件的参考资料,这让我想到了最新和最后的想法......

dismissViewControllerAnimated 是从 CDVPluginResult 调用的,引用 CDVPluginResult.viewController 而不是原始的 viewController。动作本身是动画的,这意味着需要一段时间,到那时,引用为零。或者,您似乎不应该从块中调用 dismiss,因为它不是 UI 线程。 似乎支持我的第二个理论。尝试做

dispatch_async(dispatch_get_main_queue(), ^{
        [self.viewController dismissViewControllerAnimated:YES completion:nil];
    }); 

============================================= ================================

它起作用的事实很奇怪。您将锁定变量放在 init 方法的局部上下文中,Auth0 for iOS docs 说您应该 "keep it in your AppDelegate as a strong property...keep it alive as long as you need it." 因为它是 init 中的局部变量,所以它应该在方法终止后立即释放。

也许会话检查每 x 秒进行一次,应用程序有时有足够的宽限期来工作和加载新屏幕。