Skip to content

Commit

Permalink
docs: added onDeviceResume and new DeepLinkHandler logic
Browse files Browse the repository at this point in the history
onDeviceResume is required for Android background (cordova only).
renamed DeepLinkHandler section to deprecated
  • Loading branch information
ethanneff committed Nov 18, 2016
1 parent b5654cb commit c69ef56
Showing 1 changed file with 76 additions and 79 deletions.
155 changes: 76 additions & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- [Install Branch](#install-branch)
- [Configure App](#configure-app)
- [Initialize Branch](#initialize-branch)
- [Listen Deep Link](#listen-deep-link)
- [Test Deep Link iOS](#test-deep-link-ios)
- [Test Deep Link Android](#test-deep-link-android)
- [Features](#features)
Expand Down Expand Up @@ -102,109 +101,92 @@

- <details><summary>Cordova and PhoneGap</summary>
```js
// sample index.js
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener("deviceready", this.onDeviceReady, false);
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener('resume', this.onDeviceReady, false);
},
onDeviceReady: function() {
BranchInit(true);
app.branchInit();
},
function BranchInit(isDebug) {
Branch.setDebug(isDebug); // for development and debugging only
Branch.initSession().then(function(res) {
console.log(res);
}).catch(function(err) {
console.error(err);
onDeviceResume: function() {
app.branchInit();
},
branchInit: function() {
// Branch initialization
Branch.initSession(function(data) {
// read deep link data on click
alert('Deep Link Data: ' + JSON.stringify(data));
});
}
};
app.initialize();
```
</details>

- <details><summary>Ionic 1</summary>
```js
// sample app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
$ionicPlatform.on("deviceready", function(){
BranchInit(true);
// Branch initialization
Branch.initSession(function(data) {
// read deep link data on click
alert('Deep Link Data: ' + JSON.stringify(data));
});
function BranchInit(isDebug) {
Branch.setDebug(isDebug); // for development and debugging only
Branch.initSession().then(function(res) {
console.log(res);
}).catch(function(err) {
console.error(err);
});
}
});
})
// ...
```
</details>
- <details><summary>Ionic 2</summary>
```typescript
// sample app.component.js
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { TabsPage } from '../pages/tabs/tabs';
// Branch import
declare var Branch;
@Component({
// ...
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
rootPage = TabsPage;
constructor(platform: Platform) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
// Branch
Branch.setDebug(isDebug); // for development and debugging only
Branch.initSession().then(function(res) {
console.log(res);
}).catch(function(err) {
console.error(err);
// Branch initialization
Branch.initSession(function(data) {
// read deep link data on click
alert('Deep Link Data: ' + JSON.stringify(data));
});
});
}
}
```
</details>
- #### Listen Deep Link

- `DeepLinkHandler` must be a global function and does not have to be in `index.html`

- <details><summary>Cordova and PhoneGap and Ionic</summary>
```html
<!-- sample index.html -->
<script>
// required
function DeepLinkHandler(data) {
if (data) {
alert("Data Link handler response: " + JSON.stringify(data));
}
}
// optional
function NonBranchLinkHandler(data) {
if (data) {
alert("Non-Branch Link Detected: " + JSON.stringify(data));
}
}
</script>
</body>
</html>
```
</details>
- #### Test Deep Link iOS
- Wait 15 minutes after saving changes on the [Branch Dashboard](https://dashboard.branch.io/settings/link)
Expand Down Expand Up @@ -252,14 +234,17 @@
- <details><summary>Example</summary>
```js
// for development and debugging only
Branch.setDebug(isDebug);
Branch.setDebug(true);
// sync with Mixpanel if installed
Branch.setMixpanelToken('your_mixpanel_token');
// init Branch
Branch.initSession().then(function(res) {
console.log(res);
// Branch initialization
Branch.initSession(function(data) {
// read deep link data on click
alert('Deep Link Data: ' + JSON.stringify(data));
}).then(function(res) {
alert('Response: ' + JSON.stringify(res));
}).catch(function(err) {
alert('Error: ' + JSON.stringify(err));
});
Expand Down Expand Up @@ -520,26 +505,38 @@
- Retrieve Branch data from a deep link
- Best practice to receive data from `DeepLinkHandler` listener
- Best practice to receive data from the `listener`
- <details><summary>Example (listener)</summary>
> must be global functions
```js
// required
function DeepLinkHandler(data) {
if (data) {
// window.location = "#/tab/chats/3"; // navigate to page based on data
alert("Data Link handler response: " + JSON.stringify(data));
}
}
// Branch initialization within your deviceReady
Branch.initSession(function(deepLinkData) {
// handler for deep link data on click
alert(JSON.stringify(deepLinkData));
});
```
</details>
// optional
function NonBranchLinkHandler(data) {
if (data) {
alert("Non-branch link found: " + JSON.stringify(data));
}
}
- <details><summary>Example (listener) *[depreciated]*</summary>
```html
<!-- sample index.html -->
<script>
// required
function DeepLinkHandler(data) {
if (data) {
alert('Data Link Data Response: ' + JSON.stringify(data));
}
}
// optional
function NonBranchLinkHandler(data) {
if (data) {
alert('Non-Branch Link Detected: ' + JSON.stringify(data));
}
}
</script>
</body>
</html>
```
</details>
Expand Down

0 comments on commit c69ef56

Please sign in to comment.