From c69ef5693f2ade2d01c3061fae1f70515063717c Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Fri, 18 Nov 2016 15:38:01 -0800 Subject: [PATCH] docs: added onDeviceResume and new DeepLinkHandler logic onDeviceResume is required for Android background (cordova only). renamed DeepLinkHandler section to deprecated --- README.md | 155 ++++++++++++++++++++++++++---------------------------- 1 file changed, 76 insertions(+), 79 deletions(-) diff --git a/README.md b/README.md index 9be1ec18..95bc3498 100644 --- a/README.md +++ b/README.md @@ -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) @@ -102,29 +101,29 @@ -
Cordova and PhoneGap ```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(); ```
@@ -132,45 +131,55 @@ -
Ionic 1 ```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); - }); - } }); }) + // ... ```
-
Ionic 2 ```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: `` }) - 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)); }); }); } @@ -178,33 +187,6 @@ ```
-- #### Listen Deep Link - - - `DeepLinkHandler` must be a global function and does not have to be in `index.html` - - -
Cordova and PhoneGap and Ionic - ```html - - - - - ``` -
- - #### Test Deep Link iOS - Wait 15 minutes after saving changes on the [Branch Dashboard](https://dashboard.branch.io/settings/link) @@ -252,14 +234,17 @@ -
Example ```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)); }); @@ -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` -
Example (listener) - > 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)); + }); + ``` +
- // optional - function NonBranchLinkHandler(data) { - if (data) { - alert("Non-branch link found: " + JSON.stringify(data)); - } - } + -
Example (listener) *[depreciated]* + ```html + + + + ```