2016-07-08 06:51:17 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
2016-09-22 04:04:46 +08:00
|
|
|
import { Observable } from 'rxjs/Observable';
|
2016-07-08 06:51:17 +08:00
|
|
|
|
2016-06-10 04:37:40 +08:00
|
|
|
|
|
|
|
export interface DeeplinkMatch {
|
|
|
|
/**
|
|
|
|
* The route info for the matched route
|
|
|
|
*/
|
2016-06-11 02:32:42 +08:00
|
|
|
$route: any;
|
2016-06-10 04:37:40 +08:00
|
|
|
|
|
|
|
/**
|
2016-06-11 02:32:42 +08:00
|
|
|
* Any arguments passed either through route parameters or GET parameters
|
|
|
|
*/
|
|
|
|
$args: any;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The deeplink object processed from the plugin, along with any
|
2016-06-10 04:37:40 +08:00
|
|
|
* any internal native data available as "extras" at the time
|
|
|
|
* the route was matched (for example, Facebook sometimes adds extra data)
|
|
|
|
*/
|
2016-07-08 06:51:17 +08:00
|
|
|
$link: any;
|
2016-06-10 04:37:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Ionic Deeplinks
|
|
|
|
* @description This plugin handles deeplinks on iOS and Android for both custom URL scheme links
|
|
|
|
* and Universal App Links.
|
|
|
|
*
|
|
|
|
* @usage
|
2016-07-20 23:17:09 +08:00
|
|
|
* ```typescript
|
2016-10-19 01:21:43 +08:00
|
|
|
* import { Deeplinks } from 'ionic-native';
|
2016-06-10 04:37:40 +08:00
|
|
|
*
|
2016-10-19 01:21:43 +08:00
|
|
|
* Deeplinks.route({
|
|
|
|
'/about-us': AboutPage,
|
|
|
|
'/universal-links-test': AboutPage,
|
|
|
|
'/products/:productId': ProductPage
|
|
|
|
}).subscribe((match) => {
|
|
|
|
// match.$route - the route we matched, which is the matched entry from the arguments to route()
|
|
|
|
// match.$args - the args passed in the link
|
|
|
|
// match.$link - the full link data
|
|
|
|
console.log('Successfully matched route', match);
|
|
|
|
}, (nomatch) => {
|
|
|
|
// nomatch.$link - the full link data
|
|
|
|
console.error('Got a deeplink that didn\'t match', nomatch);
|
|
|
|
});
|
2016-06-10 04:37:40 +08:00
|
|
|
* ```
|
2016-10-19 01:21:43 +08:00
|
|
|
*
|
|
|
|
* Alternatively, if you're using Ionic 2, there's a convenience method that takes a reference to a `NavController` and handles
|
|
|
|
* the actual navigation for you:
|
|
|
|
*
|
|
|
|
* ```typescript
|
|
|
|
* Deeplinks.routeWithNavController(this.navController, {
|
|
|
|
'/about-us': AboutPage,
|
|
|
|
'/products/:productId': ProductPage
|
|
|
|
});
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* See the [Ionic 2 Deeplinks Demo](https://github.com/driftyco/ionic2-deeplinks-demo/blob/master/app/app.ts) for an example of how to
|
|
|
|
* retrieve the `NavController` reference at runtime.
|
2016-06-10 04:37:40 +08:00
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-10-28 01:48:50 +08:00
|
|
|
pluginName: 'Deeplinks',
|
2016-06-10 04:37:40 +08:00
|
|
|
plugin: 'ionic-plugin-deeplinks',
|
|
|
|
pluginRef: 'IonicDeeplink',
|
2016-06-21 03:17:28 +08:00
|
|
|
repo: 'https://github.com/driftyco/ionic-plugin-deeplinks',
|
2016-08-28 03:20:51 +08:00
|
|
|
platforms: ['iOS', 'Android'],
|
|
|
|
install: 'ionic plugin add ionic-plugin-deeplinks --variable URL_SCHEME=myapp --variable DEEPLINK_SCHEME=https --variable DEEPLINK_HOST=example.com --variable ANDROID_PATH_PREFIX=/'
|
2016-06-10 04:37:40 +08:00
|
|
|
})
|
|
|
|
export class Deeplinks {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define a set of paths to match against incoming deeplinks.
|
|
|
|
*
|
|
|
|
* @param {paths} Define a set of paths to match against incoming deeplinks.
|
|
|
|
* paths takes an object of the form { 'path': data }. If a deeplink
|
|
|
|
* matches the path, the resulting path-data pair will be returned in the
|
|
|
|
* promise result which you can then use to navigate in the app as you see fit.
|
2016-11-30 06:40:50 +08:00
|
|
|
* @returns {Observable<DeeplinkMatch>} Returns an Observable that is called each time a deeplink comes through, and
|
2016-10-19 01:21:43 +08:00
|
|
|
* errors if a deeplink comes through that does not match a given path.
|
2016-06-10 04:37:40 +08:00
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true
|
|
|
|
})
|
2016-07-08 06:51:17 +08:00
|
|
|
static route(paths): Observable<DeeplinkMatch> { return; }
|
2016-06-10 04:37:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* This is a convenience version of `route` that takes a reference to a NavController
|
|
|
|
* from Ionic 2, or a custom class that conforms to this protocol:
|
|
|
|
*
|
|
|
|
* NavController.push = function(View, Params){}
|
|
|
|
*
|
|
|
|
* This handler will automatically navigate when a route matches. If you need finer-grained
|
|
|
|
* control over the behavior of a matching deeplink, use the plain `route` method.
|
|
|
|
*
|
|
|
|
* @param {paths} Define a set of paths to match against incoming deeplinks.
|
|
|
|
* paths takes an object of the form { 'path': data }. If a deeplink
|
|
|
|
* matches the path, the resulting path-data pair will be returned in the
|
|
|
|
* promise result which you can then use to navigate in the app as you see fit.
|
|
|
|
*
|
2016-12-02 07:55:59 +08:00
|
|
|
* @returns {Observable<DeeplinkMatch>} Returns an Observable that resolves each time a deeplink comes through, and
|
2016-10-19 01:21:43 +08:00
|
|
|
* errors if a deeplink comes through that does not match a given path.
|
2016-06-10 04:37:40 +08:00
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true
|
|
|
|
})
|
2016-07-08 06:51:17 +08:00
|
|
|
static routeWithNavController(navController, paths): Observable<DeeplinkMatch> { return; }
|
2016-07-20 23:17:09 +08:00
|
|
|
|
2016-06-10 04:37:40 +08:00
|
|
|
}
|