cordova-plugin-customurlscheme
Advanced tools
Comparing version
{ | ||
"name": "cordova-plugin-customurlscheme", | ||
"version": "4.0.0", | ||
"version": "4.1.1", | ||
"description": "Launch your app by using this URL: mycoolapp://, you can add a path and even pass params like this: mycoolerapp://somepath?foo=bar", | ||
@@ -43,2 +43,2 @@ "cordova": { | ||
"homepage": "https://github.com/EddyVerbruggen/Custom-URL-scheme#readme" | ||
} | ||
} |
# Custom URL scheme PhoneGap Plugin | ||
#### launch your app by a link like this: `mycoolapp://` | ||
for iOS and Android, by [Eddy Verbruggen](http://www.x-services.nl) | ||
for iOS, Android and WP, by [Eddy Verbruggen](http://www.x-services.nl) | ||
- This repo is for PhoneGap 3.0.0 and up | ||
@@ -35,2 +35,3 @@ - For PhoneGap 2.9.0 and lower, [switch to the phonegap-2.9.0-and-lower branch](https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin/tree/phonegap-2.9.0-and-lower) | ||
* Tested on Android 4.3, will most likely work with 2.2 and up. | ||
* If you're trying to launch your app from an In-App Browser it opened previously, then [use this In-App Browser plugin fork](https://github.com/Innovation-District/cordova-plugin-inappbrowser) which allows that. | ||
@@ -172,2 +173,24 @@ | ||
### CSP - or: `handleOpenURL` doesn't work | ||
The Whitelist plugin will prevent inline JS from executing, unless you whitelist the url scheme. Please see [this SO issue](http://stackoverflow.com/questions/34257097/using-handleopenurl-with-custom-url-scheme-in-cordova/34281420#34281420) for details. | ||
### Meteor | ||
When running a [meteor](meteor.com) app in the cordova environment, `handleOpenURL` doesn't get called after a cold start, because cordova resets the javascript world during startup and our timer waiting for `handleOpenURL` gets vanished (see [#98](https://github.com/EddyVerbruggen/Custom-URL-scheme/issues/98)). To get the intent by which the app was started in a meteor cordova app you need to ask for it from the meteor side with `getLastIntent` like this. | ||
```javascript | ||
Meteor.startup(function() { | ||
if (Meteor.isCordova) { | ||
window.plugins.launchmyapp.getLastIntent(function(url) { | ||
if (intent.indexOf('mycoolapp://' > -1)) { | ||
console.log("received url: " + url); | ||
} else { | ||
return console.log("ignore intent: " + url); | ||
} | ||
}, function(error) { | ||
return console.log("no intent received"); | ||
}); | ||
return; | ||
} | ||
}); | ||
``` | ||
## 4. URL Scheme hints | ||
@@ -174,0 +197,0 @@ Please choose a URL_SCHEME which which complies to these restrictions: |
@@ -7,6 +7,14 @@ (function () { | ||
function waitForAndCallHandlerFunction(url) { | ||
if (typeof window.handleOpenURL == "function") { | ||
if (typeof window.handleOpenURL === "function") { | ||
// Clear the intent when we have a handler | ||
cordova.exec( | ||
null, | ||
null, | ||
"LaunchMyApp", | ||
"clearIntent", | ||
[]); | ||
window.handleOpenURL(url); | ||
} else if (remainingAttempts-- > 0) { | ||
setTimeout(function(){waitForAndCallHandlerFunction(url)}, 500); | ||
setTimeout(function(){waitForAndCallHandlerFunction(url);}, 500); | ||
} | ||
@@ -25,2 +33,16 @@ } | ||
document.addEventListener("deviceready", triggerOpenURL, false); | ||
var launchmyapp = { | ||
getLastIntent: function(success, failure) { | ||
cordova.exec( | ||
success, | ||
failure, | ||
"LaunchMyApp", | ||
"getLastIntent", | ||
[]); | ||
} | ||
} | ||
module.exports = launchmyapp; | ||
}()); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
100177
12%15
50%240
47.24%225
11.39%