From eafc6cdfd727af9d5eea6a0868003e762a03ea9e Mon Sep 17 00:00:00 2001 From: Ethan Neff Date: Thu, 26 Apr 2018 13:33:50 -0700 Subject: [PATCH] feat: added script to build test examples --- src/scripts/examples/index.js | 118 ++++++ .../examples/templates/cordova1/index.css | 42 ++ .../examples/templates/cordova1/index.html | 69 +++ .../examples/templates/cordova1/index.js | 396 ++++++++++++++++++ .../examples/templates/cordova1/index.xml | 30 ++ .../examples/templates/ionic1/index.js | 105 +++++ .../examples/templates/ionic1/index.xml | 0 .../examples/templates/ionic3/index.html | 32 ++ .../examples/templates/ionic3/index.js | 54 +++ .../examples/templates/ionic3/index.xml | 9 + .../examples/templates/phonegap1/index.xml | 111 +++++ 11 files changed, 966 insertions(+) create mode 100644 src/scripts/examples/index.js create mode 100644 src/scripts/examples/templates/cordova1/index.css create mode 100644 src/scripts/examples/templates/cordova1/index.html create mode 100644 src/scripts/examples/templates/cordova1/index.js create mode 100644 src/scripts/examples/templates/cordova1/index.xml create mode 100644 src/scripts/examples/templates/ionic1/index.js create mode 100644 src/scripts/examples/templates/ionic1/index.xml create mode 100644 src/scripts/examples/templates/ionic3/index.html create mode 100644 src/scripts/examples/templates/ionic3/index.js create mode 100644 src/scripts/examples/templates/ionic3/index.xml create mode 100644 src/scripts/examples/templates/phonegap1/index.xml diff --git a/src/scripts/examples/index.js b/src/scripts/examples/index.js new file mode 100644 index 00000000..695ffcb9 --- /dev/null +++ b/src/scripts/examples/index.js @@ -0,0 +1,118 @@ +/* eslint-disable no-console */ + +const { spawn } = require("child_process"); + +const DIR = "examples"; +const TMP = "tmp"; +const CORDOVA1 = "cordova1"; +const PHONEGAP1 = "phonegap1"; +const IONIC1 = "ionic1"; +const IONIC3 = "ionic3"; + +// promisfy bash execution with stout streaming +const run = (args, dir = undefined) => + new Promise(resolve => { + const command = args.split(" "); + const output = spawn(command.shift(), command, { cwd: dir }); + let stdout = ""; + output.stdout.on("data", data => { + stdout += String(data); + console.log(String(data)); + }); + + output.stderr.on("data", data => { + throw new Error(String(data)); + }); + output.on("close", () => resolve(stdout.trim())); + }); + +const cleanDirectory = async () => { + await run(`rm -rf ${TMP}`); + await run(`rm -rf ${DIR}`); + await run(`mkdir ${DIR}`); +}; + +const buildCordova1 = async () => { + await run(`cordova create ${CORDOVA1}`, `${DIR}`); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.xml ./${DIR}/${CORDOVA1}/config.xml` + ); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.js ./${DIR}/${CORDOVA1}/www/js/index.js` + ); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.html ./${DIR}/${CORDOVA1}/www/index.html` + ); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.css ./${DIR}/${CORDOVA1}/www/css/index.css` + ); + + await run(`cordova plugin add ../../${TMP}`, `${DIR}/${CORDOVA1}`); + await run(`cordova platform add ios android`, `${DIR}/${CORDOVA1}`); + // cd examples/cordova1 + // (plug in devices) + // cordova run ios + // cordova run android +}; + +const buildPhoneGap1 = async () => { + await run(`phonegap create phonegap1`, `${DIR}`); + await run( + `cp ./src/scripts/examples/templates/${PHONEGAP1}/index.xml ./${DIR}/${PHONEGAP1}/config.xml` + ); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.js ./${DIR}/${PHONEGAP1}/www/js/index.js` + ); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.html ./${DIR}/${PHONEGAP1}/www/index.html` + ); + await run( + `cp ./src/scripts/examples/templates/${CORDOVA1}/index.css ./${DIR}/${PHONEGAP1}/www/css/index.css` + ); + + await run(`phonegap plugin add ../../${TMP}`, `${DIR}/${PHONEGAP1}`); + await run(`phonegap platform add ios android`, `${DIR}/${PHONEGAP1}`); + // cd examples/phonegap1 + // (plug in devices) + // phonegap run ios + // phonegap run android +}; + +const buildIonic1 = async () => { + await run(`ionic start ionic1 blank --cordova --type ionic1`, `${DIR}`); + await run(`ionic cordova plugin add ../../${TMP}`, `${DIR}/${IONIC1}`); + await run(`ionic cordova platform add ios android`, `${DIR}/${IONIC1}`); +}; + +const buildIonic3 = async () => { + await run(`ionic start ionic3 blank --cordova`, `${DIR}`); + await run(`ionic cordova plugin add ../../${TMP}`, `${DIR}/${IONIC3}`); + await run(`ionic cordova platform add ios android`, `${DIR}/${IONIC3}`); +}; + +const installDependencies = async () => { + await run("yarn add -g cordova ionic phonegap"); +}; + +const copySdk = async () => { + await run( + `rsync -a ./ ./${TMP} --exclude testbed --exclude node_modules --exclude .git --exclude ${DIR} --exclude ${TMP}` + ); +}; + +const removeCopySdk = async () => { + await run(`rm -rf ./${TMP}`); +}; + +const main = async () => { + await cleanDirectory(); + // await installDependencies(); + await copySdk(); + // await buildCordova1(); + await buildPhoneGap1(); + // await buildIonic1(); + // await buildIonic3(); + await removeCopySdk(); +}; + +module.exports = main(); diff --git a/src/scripts/examples/templates/cordova1/index.css b/src/scripts/examples/templates/cordova1/index.css new file mode 100644 index 00000000..991ce7b1 --- /dev/null +++ b/src/scripts/examples/templates/cordova1/index.css @@ -0,0 +1,42 @@ +* { + color: #303030; + box-sizing: border-box; + background-color: #ffffff !important; +} +body { + display: flex; + flex-direction: column; + padding: 1em 0em 0.5em 0em; + max-width: 40em; + margin: 0 auto; +} +fieldset { + border-color: #303030; + margin: 0.5em 1em; + padding: 0.75em; +} +fieldset > *:not(:first-child) { + margin-bottom: 0.5em; +} +fieldset > *:last-child { + margin-bottom: 0; +} +section { + display: flex; + flex-direction: row; +} +section > button:nth-child(even) { + margin-left: 0.5em; +} +section > button:nth-child(odd) { + margin-right: 0.5em; +} +button, +input { + padding: 0.5em; + border: 3px solid #f5f5f5; + width: 100%; +} +button { + background-color: #f5f5f5; +} diff --git a/src/scripts/examples/templates/cordova1/index.html b/src/scripts/examples/templates/cordova1/index.html new file mode 100644 index 00000000..bea1c0c6 --- /dev/null +++ b/src/scripts/examples/templates/cordova1/index.html @@ -0,0 +1,69 @@ + + + + + + + + + Branch Testing + + +
+ Branch Universal Object + +
+
+ Branch Deep Link + +
+ + +
+ +
+
+ Branch Deep Link Data +
+ + +
+
+
+ Branch Content +
+ + +
+
+
+ Branch User + +
+ + +
+
+
+ Branch Event + +
+ + +
+
+
+ Branch Referral +
+ + +
+
+ + +
+
+ + + + diff --git a/src/scripts/examples/templates/cordova1/index.js b/src/scripts/examples/templates/cordova1/index.js new file mode 100644 index 00000000..da873783 --- /dev/null +++ b/src/scripts/examples/templates/cordova1/index.js @@ -0,0 +1,396 @@ +// app +var app = { + initialize: function initialize() { + app.bindEvents(); + }, + bindEvents: function bindEvents() { + document.addEventListener("deviceready", app.onDeviceReady, false); + document.addEventListener("resume", app.onDeviceResume, false); + }, + onDeviceReady: function onDeviceReady() { + BranchInit(); + }, + onDeviceResume: function onDeviceResume() { + BranchInit(); + } +}; + +var branchUniversalObj = null; + +// cache DOM +var branchUniversalObject = document.getElementById("branchUniversalObject"); +var branchDeepLink = document.getElementById("branchDeepLink"); +var branchShareSheet = document.getElementById("branchShareSheet"); +var branchFirstData = document.getElementById("branchFirstData"); +var branchLatestData = document.getElementById("branchLatestData"); +var branchView = document.getElementById("branchView"); +var branchSpotlight = document.getElementById("branchSpotlight"); +var branchUser = document.getElementById("branchUser"); +var branchLogout = document.getElementById("branchLogout"); +var branchEvent = document.getElementById("branchEvent"); +var branchCommerce = document.getElementById("branchCommerce"); +var branchReferralsReward = document.getElementById("branchReferralsReward"); +var branchReferralsLoad = document.getElementById("branchReferralsLoad"); +var branchReferralsRedeem = document.getElementById("branchReferralsRedeem"); +var branchReferralsHistory = document.getElementById("branchReferralsHistory"); + +// handle DOM +branchUniversalObject.addEventListener("click", BranchUniversalObject); +branchDeepLink.addEventListener("click", BranchDeepLink); +branchShareSheet.addEventListener("click", BranchShareSheet); +branchFirstData.addEventListener("click", BranchFirstData); +branchLatestData.addEventListener("click", BranchLatestData); +branchView.addEventListener("click", BranchView); +branchSpotlight.addEventListener("click", BranchSpotlight); +branchUser.addEventListener("click", BranchUser); +branchLogout.addEventListener("click", BranchLogout); +branchEvent.addEventListener("click", BranchEvent); +branchCommerce.addEventListener("click", BranchCommerce); +branchReferralsReward.addEventListener("click", BranchReferralsReward); +branchReferralsLoad.addEventListener("click", BranchReferralsLoad); +branchReferralsRedeem.addEventListener("click", BranchReferralsRedeem); +branchReferralsHistory.addEventListener("click", BranchReferralsHistory); + +// run +app.initialize(); + +// logger +function logger(message, isError) { + var header = isError ? "Error" : "Response"; + var output = header + ": " + JSON.stringify(message); + console.log(output); + alert(output); +} + +// branch +function BranchInit() { + // for development and debugging only + Branch.setDebug(true); + + // for GDPR compliance (can be called at anytime) + Branch.disableTracking(false); + + // for better Android matching + Branch.setCookieBasedMatching("cordova.app.link"); + + // sync with Mixpanel if installed + Branch.setRequestMetadata("$mixpanel_distinct_id", "your_mixpanel_token"); + + // Branch initialization + Branch.initSession() + .then(function success(res) { + if (res["+clicked_branch_link"]) { + alert("Open app with a Branch deep link: " + JSON.stringify(res)); + // Branch quick link: https://cordova.app.link/uJcOH1IFpM + // Branch web link: https://cordova-alternate.app.link/uJcOH1IFpM + // Branch dynamic link: https://cordova.app.link?tags=one&tags=two&tags=three&channel=Copy&feature=onboarding&stage=new+user&campaign=content+123+launch&type=0&duration=0&source=android&data + // Branch uri scheme: branchcordova://open?link_click_id=link-500015444967786346 + // Branch android intent: intent://open?link_click_id=518106399270344237#Intent;scheme=looprocks;package=com.eneff.branch.cordovatestbed;S.browser_fallback_url=https%3A%2F%2Fcordova.app.link%2FuJcOH1IFpM%3F__branch_flow_type%3Dchrome_deepview%26__branch_flow_id%3D518106399312287278;S.market_referrer=link_click_id-518106399270344237%26utm_source%3DCopy%26utm_campaign%3Dcontent%20123%20launch%26utm_feature%3Donboarding;S.branch_data=%7B%22~feature%22%3A%22onboarding%22%2C%22this_is%22%3A%22true%22%2C%22custom_string%22%3A%22data%22%2C%22testing%22%3A%22123%22%2C%22%24publicly_indexable%22%3A%22false%22%2C%22%24desktop_url%22%3A%22http%3A%2F%2Fwww.example.com%2Fdesktop%22%2C%22%24one_time_use%22%3Afalse%2C%22custom_object%22%3A%22%7B%5C%5C%5C%22random%5C%5C%5C%22%3A%5C%5C%5C%22dictionary%5C%5C%5C%22%7D%22%2C%22~id%22%3A%22517795540654792902%22%2C%22~campaign%22%3A%22content%20123%20launch%22%2C%22%2Bclick_timestamp%22%3A1524764418%2C%22%2Burl%22%3A%22https%3A%2F%2Fcordova.app.link%2FuJcOH1IFpM%22%2C%22custom_boolean%22%3A%22true%22%2C%22custom%22%3A%22data%22%2C%22source%22%3A%22android%22%2C%22%24og_image_url%22%3A%22http%3A%2F%2Florempixel.com%2F400%2F400%2F%22%2C%22%2Bdomain%22%3A%22cordova.app.link%22%2C%22custom_integer%22%3A%221524690301794%22%2C%22~tags%22%3A%5B%22one%22%2C%22two%22%2C%22three%22%5D%2C%22custom_array%22%3A%22%5B1%2C2%2C3%2C4%2C5%5D%22%2C%22~channel%22%3A%22Copy%22%2C%22~creation_source%22%3A2%2C%22%24canonical_identifier%22%3A%22content%2F123%22%2C%22%24og_title%22%3A%22Content%20123%20Title%22%2C%22%24og_description%22%3A%22Content%20123%20Description%201524690296449%22%2C%22%24identity_id%22%3A%22453670943617990547%22%2C%22~stage%22%3A%22new%20user%22%2C%22%2Bclicked_branch_link%22%3Atrue%2C%22%2Bmatch_guaranteed%22%3Atrue%2C%22%2Bis_first_session%22%3Afalse%7D;B.branch_intent=true;end + // Branch android app link (device controlled): https://cordova.app.link/uJcOH1IFpM + // Branch ios universal link (device controlled): https://cordova.app.link/uJcOH1IFpM + } else if (res["+non_branch_link"]) { + alert("Open app with a non Branch deep link: " + JSON.stringify(res)); + // Competitor uri scheme: anotherurischeme://hello=world + } else { + alert("Open app organically"); + // Clicking on app icon or push notification + } + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchEvent() { + // event name + var event = document.getElementById("custom-action").value; + + // optional + var metadata = { + custom_dictionary: 123, + anything: "everything" + }; + + Branch.userCompletedAction(event, metadata) + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchCommerce() { + // revenue required + var event = { + revenue: 50.29, + currency: 148, // USD + transactionID: "transaction id", + coupon: "coupon", + shipping: 2.22, + tax: 5.11, + affiliation: "affiliation", + products: [ + { + sku: "u123", + name: "cactus", + price: 4.99, + quantity: 2, + brand: "brand", + category: 17, // Software + variant: "variant" + }, + { + sku: "u456", + name: "grass", + price: 0.0, + quantity: 1 + } + ] + }; + + // optional + var metadata = { + custom_dictionary: 123, + anything: "everything" + }; + + Branch.sendCommerceEvent(event, metadata) + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchFirstData() { + Branch.getFirstReferringParams() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchLatestData() { + Branch.getLatestReferringParams() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchUser() { + var userId = document.getElementById("identity").value; + Branch.setIdentity(userId) + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchLogout() { + Branch.logout() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchUniversalObject() { + // only canonicalIdentifier is required + var properties = { + canonicalIdentifier: "content/123", + canonicalUrl: "https://example.com/content/123", + title: "Content 123 Title", + contentDescription: "Content 123 Description " + Date.now(), + contentImageUrl: "http://lorempixel.com/400/400/", + price: 12.12, + currency: "GBD", + contentIndexingMode: "private", + contentMetadata: { + custom: "data", + testing: 123, + this_is: true + } + }; + + // create a branchUniversalObj variable to reference with other Branch methods + Branch.createBranchUniversalObject(properties) + .then(function success(res) { + branchUniversalObj = res; + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchView() { + if (branchUniversalObj === null) { + alert("need to Generate Branch Universal Object"); + return; + } + branchUniversalObj + .registerView() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchDeepLink() { + // optional fields + var analytics = { + channel: "facebook", + feature: "onboarding", + campaign: "content 123 launch", + stage: "new user", + tags: ["one", "two", "three"], + alias: document.getElementById("alias").value + }; + + // optional fields + var properties = { + $desktop_url: "http://www.example.com/desktop", + $android_url: "http://www.example.com/android", + $ios_url: "http://www.example.com/ios", + $ipad_url: "http://www.example.com/ipad", + $deeplink_path: "content/123", + $match_duration: 2000, + custom_string: "data", + custom_integer: Date.now(), + custom_boolean: true + }; + + // needs a universal object + if (branchUniversalObj === null) { + alert("need to Generate Branch Universal Object"); + return; + } + + branchUniversalObj + .generateShortUrl(analytics, properties) + .then(function success(res) { + document.getElementById("generated-url").placeholder = ""; + document.getElementById("generated-url").value = res.url; + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchShareSheet() { + // optional fields + var analytics = { + channel: "facebook", + feature: "onboarding", + campaign: "content 123 launch", + stage: "new user", + tags: ["one", "two", "three"] + }; + + // optional fields + var properties = { + $desktop_url: "http://www.example.com/desktop", + custom_string: "data", + custom_integer: Date.now(), + custom_boolean: true, + custom_array: [1, 2, 3, 4, 5], + custom_object: { random: "dictionary" } + }; + + var message = "Check out this link"; + + // needs a universal object + if (branchUniversalObj === null) { + alert("need to Generate Branch Universal Object"); + return; + } + + // optional listeners (must be called before showShareSheet) + branchUniversalObj.onShareSheetLaunched(function success(res) { + // android only + console.log(res); + }); + branchUniversalObj.onShareSheetDismissed(function success(res) { + console.log(res); + }); + branchUniversalObj.onLinkShareResponse(function success(res) { + console.log(res); + }); + branchUniversalObj.onChannelSelected(function success(res) { + // android only + console.log(res); + }); + + // share sheet + branchUniversalObj.showShareSheet(analytics, properties, message); +} + +function BranchSpotlight() { + if (branchUniversalObj === null) { + alert("need to Generate Branch Universal Object"); + return; + } + branchUniversalObj + .listOnSpotlight() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchReferralsReward() { + Branch.userCompletedAction("add5credits") + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchReferralsLoad() { + Branch.loadRewards() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchReferralsRedeem() { + var amount = 10; + Branch.redeemRewards(amount) + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} + +function BranchReferralsHistory() { + Branch.creditHistory() + .then(function success(res) { + logger(res); + }) + .catch(function error(err) { + logger(err, true); + }); +} diff --git a/src/scripts/examples/templates/cordova1/index.xml b/src/scripts/examples/templates/cordova1/index.xml new file mode 100644 index 00000000..908699a2 --- /dev/null +++ b/src/scripts/examples/templates/cordova1/index.xml @@ -0,0 +1,30 @@ + + + + + + + + + + Cordova1 + Testing App For Branch Cordova + Branch Support + + + + + + + + + + + + + + + + + + diff --git a/src/scripts/examples/templates/ionic1/index.js b/src/scripts/examples/templates/ionic1/index.js new file mode 100644 index 00000000..9163953d --- /dev/null +++ b/src/scripts/examples/templates/ionic1/index.js @@ -0,0 +1,105 @@ +// Ionic Starter App + +// angular.module is a global place for creating, registering and retrieving Angular modules +// 'starter' is the name of this angular module example (also set in a attribute in index.html) +// the 2nd parameter is an array of 'requires' +// 'starter.services' is found in services.js +// 'starter.controllers' is found in controllers.js +angular + .module("starter", ["ionic", "starter.controllers", "starter.services"]) + + .run(function($ionicPlatform) { + $ionicPlatform.ready(function() { + // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard + // for form inputs) + if ( + window.cordova && + window.cordova.plugins && + window.cordova.plugins.Keyboard + ) { + cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); + cordova.plugins.Keyboard.disableScroll(true); + } + if (window.StatusBar) { + // org.apache.cordova.statusbar required + StatusBar.styleDefault(); + } + + // Branch + $ionicPlatform.on("deviceready", function() { + branchInit(); + }); + + $ionicPlatform.on("resume", function() { + branchInit(); + }); + + function branchInit() { + // Branch initialization + Branch.setDebug(true); + Branch.initSession(function(data) { + // read deep link data on click + alert("Deep Link Data: " + JSON.stringify(data)); + }); + } + }); + }) + + .config(function($stateProvider, $urlRouterProvider) { + // Ionic uses AngularUI Router which uses the concept of states + // Learn more here: https://github.com/angular-ui/ui-router + // Set up the various states which the app can be in. + // Each state's controller can be found in controllers.js + $stateProvider + + // setup an abstract state for the tabs directive + .state("tab", { + url: "/tab", + abstract: true, + templateUrl: "templates/tabs.html" + }) + + // Each tab has its own nav history stack: + + .state("tab.dash", { + url: "/dash", + views: { + "tab-dash": { + templateUrl: "templates/tab-dash.html", + controller: "DashCtrl" + } + } + }) + + .state("tab.chats", { + url: "/chats", + views: { + "tab-chats": { + templateUrl: "templates/tab-chats.html", + controller: "ChatsCtrl" + } + } + }) + .state("tab.chat-detail", { + url: "/chats/:chatId", + views: { + "tab-chats": { + templateUrl: "templates/chat-detail.html", + controller: "ChatDetailCtrl" + } + } + }) + + .state("tab.account", { + url: "/account", + views: { + "tab-account": { + templateUrl: "templates/tab-account.html", + controller: "AccountCtrl" + } + } + }); + + // if none of the above states are matched, use this as the fallback + $urlRouterProvider.otherwise("/tab/dash"); + }); diff --git a/src/scripts/examples/templates/ionic1/index.xml b/src/scripts/examples/templates/ionic1/index.xml new file mode 100644 index 00000000..e69de29b diff --git a/src/scripts/examples/templates/ionic3/index.html b/src/scripts/examples/templates/ionic3/index.html new file mode 100644 index 00000000..502ee691 --- /dev/null +++ b/src/scripts/examples/templates/ionic3/index.html @@ -0,0 +1,32 @@ + + + Home + + + + +

Welcome to Ionic!

+

+ This starter project comes with simple tabs-based layout for apps + that are going to primarily use a Tabbed UI. +

+

+ Take a look at the src/pages/ directory to add or change tabs, + update any existing page or create new pages. +

+ + + Link + + + + + + + + + + + + +
diff --git a/src/scripts/examples/templates/ionic3/index.js b/src/scripts/examples/templates/ionic3/index.js new file mode 100644 index 00000000..b815d995 --- /dev/null +++ b/src/scripts/examples/templates/ionic3/index.js @@ -0,0 +1,54 @@ +import { Component } from '@angular/core'; +import { Platform } from 'ionic-angular'; +import { StatusBar } from '@ionic-native/status-bar'; +import { SplashScreen } from '@ionic-native/splash-screen'; +import { TabsPage } from '../pages/tabs/tabs'; +import { AlertController } from 'ionic-angular'; +import { Storage } from '@ionic/storage'; + +@Component({ + templateUrl: 'app.html' +}) +export class MyApp { + rootPage:any = TabsPage; + + constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private alertCtrl: AlertController, private storage: Storage) { + platform.ready().then(() => { + statusBar.styleDefault(); + splashScreen.hide(); + handleBranch(); + }); + platform.resume.subscribe(() => { + handleBranch(); + }); + // Branch initialization + const handleBranch = () => { + // only on devices + if (!platform.is('cordova')) { return } + const Branch = window['Branch']; + Branch.initSession(data => { + // read deep link data on click + if (data['+clicked_branch_link']) { + // save to device + storage.set('branch', data).then(() => { + // do something with it + showAlert(); + }); + } + }); + } + // ionic 2/3 component + const showAlert = () => { + // read from device + storage.get('branch').then((val) => { + // show alert + let alert = this.alertCtrl.create({ + title: 'Branch Data', + subTitle: JSON.stringify(val), + buttons: ['OK'] + }); + alert.present(); + }); + } + } +} diff --git a/src/scripts/examples/templates/ionic3/index.xml b/src/scripts/examples/templates/ionic3/index.xml new file mode 100644 index 00000000..1c34da80 --- /dev/null +++ b/src/scripts/examples/templates/ionic3/index.xml @@ -0,0 +1,9 @@ + + + + + + + + + Ionic3 \ No newline at end of file diff --git a/src/scripts/examples/templates/phonegap1/index.xml b/src/scripts/examples/templates/phonegap1/index.xml new file mode 100644 index 00000000..2241cd50 --- /dev/null +++ b/src/scripts/examples/templates/phonegap1/index.xml @@ -0,0 +1,111 @@ + + + + + + + + + + PhoneGap1 + PhoneGap1 + Branch Support + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +