Skip to content

Instantly share code, notes, and snippets.

@phund
Last active August 30, 2016 07:41
Show Gist options
  • Save phund/b168211138d042be134e8122c515a177 to your computer and use it in GitHub Desktop.
Save phund/b168211138d042be134e8122c515a177 to your computer and use it in GitHub Desktop.
Meteor use deeplink with cordova-plugin-customurlscheme@4.1.3
  1. Add cordova plugin meteor add cordova:cordova-plugin-customurlscheme@4.1.3
  2. Add config on mobile-config.js App.configurePlugin('cordova-plugin-customurlscheme', { URL_SCHEME: '<name_of_scheme (ex: openapp => openapp://link/to/path)>' });
  3. Add handle open url function on js window.handleOpenURL = function handleOpenURL(receiveUrl) { setTimeout(function() { let url = receiveUrl; if (typeof window._saveOpenURL != "undefined") { url = window._saveOpenURL; } // handle url here..... }, 0); };
  4. Build on IOS fix cold start app not run handleOpenURL

References:

  https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/154
  https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/2#issuecomment-152557017

in Xcode on CDVHanleOpenURL.m comment line self.url = nil on (void)applicationPageDidLoad:(NSNotification*)notification ``` - (void)applicationPageDidLoad:(NSNotification*)notification { // cold-start handler

    self.pageLoaded = YES;

    if (self.url) {
        [self processOpenUrl:self.url pageLoaded:YES];
//        self.url = nil; <==== this line
    }
}
```
Changed

  ```
  NSString* jsString = [NSString stringWithFormat:@"document.addEventListener('deviceready',function(){if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}});", url];
  ```
  
to

  ```
  NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");} else { window._savedOpenURL = \"%@\"; }", url, url];
  ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment