Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova view unresponsive after plugin returns

I'm trying to make auth0 lock for iOS work with cordova. It seems to work except I'm doing something wrong when I'm dismissing the view after the plugin is done. It gets dismissed but I can no longer interact with the cordova view. It becomes unresponsive.

Here is the plugin code:

@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
like image 832
Kerim Incedayi Avatar asked May 17 '16 13:05

Kerim Incedayi


1 Answers

I have to admit your code looks good and I can't find anything wrong with it or on Google. I did find some references to race condition, which brings me to the latest and last idea...

dismissViewControllerAnimated is called from CDVPluginResult with a reference to CDVPluginResult.viewController and not the original viewController. The action itself is animated, which means takes a while and by that time, the reference is to nil. Alternatively, it seems you shouldn't call dismiss from a block, as it isn't the UI thread. This seems to support my second theory. Try doing

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

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

The fact that it works is weird. You're placing your lock variable in a local context within the init method and the Auth0 for iOS docs say you should "keep it in your AppDelegate as a strong property...keep it alive as long as you need it." Since it's a local variable in init, it should be deallocated as soon as the method terminates.

Perhaps the session check is made every x seconds and the app sometimes has enough grace period to work and load the new screen.

like image 194
Roy Falk Avatar answered Sep 23 '22 18:09

Roy Falk