使用ionic-plugin-deeplink插件后,发现qq登录和微信登录都不能使用,连接xcode调试后, 发现openurl方法被ionic-plugin-deeplink插件拦截了。

看了一下代码:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    IonicDeeplinkPlugin *plugin = [self.viewController getCommandInstance:PLUGIN_NAME];

    if(plugin == nil) {
      NSLog(@"Unable to get instance of command plugin");
      return NO;
    }

    BOOL handled = [plugin handleLink:url];

    if(!handled) {
      // Pass event through to Cordova
      [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];

      // Send notice to the rest of our plugin that we didn't handle this URL
      [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"IonicLinksUnhandledURL" object:[url absoluteString]]];
    }

    return YES;
}

然后就是这个handleLink方法

- (BOOL)handleLink:(NSURL *)url {    - (BOOL)handleLink:(NSURL *)url {
   NSLog(@"IonicDeepLinkPlugin: Handle link (internal) %@", url);    
    _lastEvent = [self createResult:url];     
    [self sendToJs];       
    return YES;    
 }

一直返回的是YES,这下有趣了,那么上面的if(!handled)方法里面给cordova插件发送postNotification就不会执行,那么其他诸如微信、qq插件都不会收到openurl的回调。

一切都水落石出了,那么解决也很简单,你可以直接把if(!handled) {的条件判断去掉,

当然,更合理的方法,就是判断传入的url是否为我们想要的url链接或scheme,然后进行过滤, 我已经把相关代码提交了PR,后面看官方怎么回应把。

https://github.com/ionic-team/ionic-plugin-deeplinks/pull/172