https://github.com/nativescript/nativescript-urlhandler
NativeScript URL Handler Plugin
https://github.com/nativescript/nativescript-urlhandler
Last synced: 8 months ago
JSON representation
NativeScript URL Handler Plugin
- Host: GitHub
- URL: https://github.com/nativescript/nativescript-urlhandler
- Owner: NativeScript
- License: mit
- Archived: true
- Fork: true (hypery2k/nativescript-urlhandler)
- Created: 2018-10-24T08:59:05.000Z (over 7 years ago)
- Default Branch: develop
- Last Pushed: 2018-10-25T17:12:12.000Z (over 7 years ago)
- Last Synced: 2024-05-23T10:01:13.003Z (about 2 years ago)
- Language: TypeScript
- Size: 2.4 MB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# NativeScript URL Handler Plugin  
[](https://greenkeeper.io/)
[](https://travis-ci.org/hypery2k/nativescript-urlhandler)
[](bitcoin:3NKtxw1SRYgess5ev4Ri54GekoAgkR213D)
[](http://badge.fury.io/js/nativescript-urlhandler)[](https://codeclimate.com/github/hypery2k/nativescript-urlhandler/maintainability)
[](https://nodei.co/npm/nativescript-urlhandler/)
> Feel free to **donate**
>
>
>
>
> Or donate Bitcoins: bitcoin:3NKtxw1SRYgess5ev4Ri54GekoAgkR213D
>
> [](bitcoin:3NKtxw1SRYgess5ev4Ri54GekoAgkR213D)
>
> Also via [greenaddress](https://greenaddress.it/pay/GA3ZPfh7As3Gc2oP6pQ1njxMij88u/)
# Usage
Just add App links to your app, see iOS and Android instructions below, and register a handler for the URL data.
See this example for Angular:
```typescript
import { Component, OnInit } from "@angular/core";
import { handleOpenURL, AppURL } from 'nativescript-urlhandler';
@Component({
selector: "gr-main",
template: ""
})
export class AppComponent {
constructor() {
}
ngOnInit(){
handleOpenURL((appURL: AppURL) => {
console.log('Got the following appURL', appURL);
});
}
}
```
And for pure NativeScript:
```javascript
var handleOpenURL = require("nativescript-urlhandler").handleOpenURL;
handleOpenURL(function(appURL) {
console.log('Got the following appURL', appURL);
});
```
Or as TypeScript:
```typescript
import { handleOpenURL, AppURL } from 'nativescript-urlhandler';
handleOpenURL((appURL: AppURL) => {
console.log('Got the following appURL', appURL);
});
```
## Installation
```bash
$ tns plugin add nativescript-urlhandler
```
Or if you want to use the development version (nightly build), which maybe not stable!:
```bash
$ tns plugin add nativescript-urlhandler@next
```
### Android
Replace *myapp* with your desired scheme and set launchMode to *singleTask*
```xml
...
```
For example:
```xml
```
The android:launchMode="singleTask" tells the Android operating system to launch the app with a new instance of the activity, or use an existing one. Without this your app will launch multiple instances of itself which is no good.
### iOS
```xml
CFBundleURLTypes
CFBundleURLName
com.yourcompany.myapp
CFBundleURLSchemes
myapp
```
# FAQ
## Callback handling
The "handleOpenURL" callback must be called before application initialization, otherwise you'll see this error in the console:
```
No callback provided. Please ensure that you called "handleOpenURL" during application init!
```
## Webpack
### TypeScript Config
If your Webpack Build is failing, try adapting your tsconfig to this:
```
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"lib": [
"es6",
"dom",
"es2015.iterable"
],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
},
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts"
]
```