Skip to content

Commit 8585d6d

Browse files
authored
Merge pull request #237 from BranchMetrics/refactor/no-global-hooks
Refactor/no global hooks
2 parents 7dc2eff + abb06db commit 8585d6d

File tree

7 files changed

+530
-384
lines changed

7 files changed

+530
-384
lines changed

README.md

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,6 @@ If your links are of the form `bnc.lt`, you must still use this domain in your c
117117
```
118118
`READ_FROM_DASHBOARD` is the four-character value in front of all your links. You can find it underneath the field labeled SHA256 Cert Fingerprints on the [dashboard](https://dashboard.branch.io/settings/link). It will look something like this: `/WSuf` (the initial `/` character should be included).
119119

120-
---------------
121-
122-
## Non-Branch Links
123-
There are instances where non-branch links are detected by the plugin but not processed.
124-
You can retrieve the url by implementing the method `NonBranchLinkHandler()` which will act as our callback to return the non-branch url.
125-
126-
To implement:
127-
128-
```js
129-
function NonBranchLinkHandler(data) {
130-
if (data) {
131-
alert('Non-Branch Link Detected: ' + JSON.stringify(data));
132-
}
133-
}
134-
```
135-
---------------
136-
137120
## Promises
138121

139122
**Most methods are promisified**, therefore you can easily get its success and error callback by chaining the `.then()` method.
@@ -153,6 +136,7 @@ Branch.getFirstReferringParams().then(function (res) {
153136

154137
1. Branch Session
155138
+ [setDebug](#setDebug)
139+
+ [onNonBranchLink](#onNonBranchLink)
156140
+ [initSession](#initSession)
157141
+ [setMixpanelToken](#setMixpanelToken)
158142
+ [getLatestReferringParams](#getLatestReferringParams)
@@ -172,6 +156,9 @@ Branch.getFirstReferringParams().then(function (res) {
172156
+ [creditHistory](#creditHistory)
173157
4. FAQ
174158
+ [Android Build FAQ](#android-build-faq)
159+
5. Deprecated Methods
160+
+ [Gobal Event Listeners](#deprecated-event-listeners)
161+
+ [disableGlobalListenersWarnings](#disableGlobalListenersWarnings)
175162

176163
### <a id="setDebug"></a>setDebug(isEnable)
177164

@@ -187,40 +174,46 @@ Setting the SDK debug flag will generate a new device ID each time the app is in
187174
Branch.setDebug(true);
188175
```
189176

190-
### <a id="initSession"></a>initSession()
191-
192-
Initializes the branch instance. **Note:** `setDebug()` should be called first before calling this method.
177+
### <a id="onNonBranchLink"></a>onNonBranchLink(hook)
178+
There are instances where non-branch links are detected by the plugin but not processed.
179+
You can retrieve the url by calling the method `onNonBranchLink(hook)` which will register
180+
a callback to receive the non-branch url.
193181

194182
##### Usage
195-
The `initSession()` method automatically sets an internal deep link hander whose data can be accesed by implementing the **required** `DeepLinkHandler()` method. To implement this, first call the method `initSession`:
196-
197183
```js
198-
onDeviceReady: function() {
199-
Branch.initSession();
200-
},
201-
onResume: function() {
202-
Branch.initSession();
203-
},
204-
initialize: function() {
205-
document.addEventListener('deviceready', onDeviceReady, false);
206-
document.addEventListener('resume', onResume, false);
207-
},
184+
branch.onNonBranchLink(function NonBranchLinkHandler(data) {
185+
if (data) {
186+
alert('Non-Branch Link Detected: ' + JSON.stringify(data));
187+
}
188+
});
208189
```
209190

210-
Then you should **EXPLICITLY** define a global method called `DeepLinkHandler()` which will act as our callback when the session beings. The deep link data will be included here:
191+
### <a id="initSession"></a>initSession(onBranchLinkHook)
192+
193+
Initializes the branch instance. **Note:** `setDebug()` should be called first before calling this method. Takes a listener that will be triggered on opening of a branch link.
194+
195+
##### Usage
211196

212197
```js
213-
function DeepLinkHandler(data) {
198+
function onBranchLinkHook(data) {
214199
if (data) {
215200
alert('Data from deep link: ' + JSON.stringify(data));
216201
} else {
217202
alert('No data found');
218203
}
219204
}
205+
onDeviceReady: function() {
206+
Branch.initSession(onBranchLinkHook);
207+
},
208+
onResume: function() {
209+
Branch.initSession(onBranchLinkHook);
210+
},
211+
initialize: function() {
212+
document.addEventListener('deviceready', onDeviceReady, false);
213+
document.addEventListener('resume', onResume, false);
214+
},
220215
```
221216

222-
Note, if you are unsure how to set a global function or you are getting a `Reference not defined` error with `DeepLinkHandler`, please review this [Github issue](https://github.com/BranchMetrics/cordova-ionic-phonegap-branch-deep-linking/issues/128).
223-
224217
### <a id="setMixpanelToken"></a>setMixpanelToken()
225218

226219
This method allows the Branch SDK to pass the user's Mixpanel distinct id to our servers. Branch will then pass that Distinct ID to Mixpanel when logging any event.
@@ -683,6 +676,29 @@ Go to your `build.gradle` file and find **dependencies** and add the following i
683676
compile "io.branch.sdk.android:library:2.+"
684677
```
685678

679+
## Deprecated Methods
680+
681+
### <a id="deprecated-event-listeners"></a>Gobal Event Listeners
682+
683+
Before version 2.4.0 Branch used globaly defined listeners to pass events generated
684+
by clicking on links outside your cordova app into it. To make this behavior more
685+
explicit, we've shifted to event listeners passed to the branch object via the
686+
[`branch.initSession(onBranchLinkHook)`](#initSession) and
687+
[`branch.onNonBranchLink(hook)`](#onNonBranchLink). If you don't want to use these
688+
new methods and instead prefer the old global hooks without seeing warnings, call
689+
[`branch.disableGlobalListenersWarning()`](#disableGlobalListenersWarnings).
690+
691+
### <a id="disableGlobalListenersWarnings"></a>disableGlobalListenersWarnings
692+
693+
This method turns off warnings about using global listeners instead of hooks passed
694+
to methods. It also disables warnings about overwriting global listeners with hooks
695+
passed to methods.
696+
697+
##### Usage
698+
```js
699+
branch.disableGlobalListenersWarnings();
700+
```
701+
686702
## Bugs / Help / Support
687703

688704
Feel free to report any bugs you might encounter in the repo's issues. Any support inquiries outside of bugs

plugin.template.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SOFTWARE.
2626
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2727
xmlns:android="http://schemas.android.com/apk/res/android"
2828
id="io.branch.sdk"
29-
version="2.3.2">
29+
version="2.4.0">
3030

3131
<name>branch-cordova-sdk</name>
3232
<description>Branch SDK Plugin</description>

plugin.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ SOFTWARE.
2626
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2727
xmlns:android="http://schemas.android.com/apk/res/android"
2828
id="io.branch.sdk"
29-
version="2.3.2">
29+
version="2.4.0">
3030

3131
<name>branch-cordova-sdk</name>
3232
<description>Branch SDK Plugin</description>
@@ -105,14 +105,14 @@ SOFTWARE.
105105
<header-file src="src/ios/BranchSDK.h" />
106106
<source-file src="src/ios/BranchSDK.m" />
107107
<source-file src="src/ios/AppDelegate+BranchSdk.m" />
108-
108+
109109
<header-file src="src/ios/dependencies/Fabric/ANSCompatibility.h" />
110110
<header-file src="src/ios/dependencies/Fabric/Answers.h" />
111111
<header-file src="src/ios/dependencies/Fabric/FABAttributes.h" />
112112
<header-file src="src/ios/dependencies/Fabric/FABKitProtocol.h" />
113113
<header-file src="src/ios/dependencies/Fabric/Fabric+FABKits.h" />
114114
<header-file src="src/ios/dependencies/Fabric/Fabric.h" />
115-
115+
116116
<header-file src="src/ios/dependencies/Branch-SDK/BNCCallbacks.h" />
117117
<header-file src="src/ios/dependencies/Branch-SDK/BNCConfig.h" />
118118
<header-file src="src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.h" />
@@ -167,7 +167,7 @@ SOFTWARE.
167167
<source-file src="src/ios/dependencies/Branch-SDK/BranchView.m" />
168168
<header-file src="src/ios/dependencies/Branch-SDK/BranchViewHandler.h" />
169169
<source-file src="src/ios/dependencies/Branch-SDK/BranchViewHandler.m" />
170-
170+
171171
<header-file src="src/ios/dependencies/Branch-SDK/Requests/BNCServerRequest.h" />
172172
<source-file src="src/ios/dependencies/Branch-SDK/Requests/BNCServerRequest.m" />
173173
<header-file src="src/ios/dependencies/Branch-SDK/Requests/BranchCloseRequest.h" />
@@ -197,6 +197,6 @@ SOFTWARE.
197197
<header-file src="src/ios/dependencies/Branch-SDK/Requests/BranchUserCompletedActionRequest.h" />
198198
<source-file src="src/ios/dependencies/Branch-SDK/Requests/BranchUserCompletedActionRequest.m" />
199199
<header-file src="src/ios/dependencies/Branch-SDK/Requests/PromoViewHandler.h" />
200-
200+
201201
</platform>
202202
</plugin>

0 commit comments

Comments
 (0)