Skip to content

Commit

Permalink
Merge pull request #92 from BranchMetrics/fix/issue-80-fix-ios-plugin…
Browse files Browse the repository at this point in the history
…-issues

Fix/issue 80 fix ios plugin issues
  • Loading branch information
aaustin committed Apr 5, 2016
2 parents 9e43086 + bc304b1 commit 12c447f
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 225 deletions.
76 changes: 47 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ If you use a custom domain or subdomain for your Branch links, you should also a

## Plugin Methods

**Some methods are promisified**, therefore you can easily get its success and error callback by chaining `.then()` method.
**Most methods are promisified**, therefore you can easily get its success and error callback by chaining `.then()` method.

*Example*
```js
Expand Down Expand Up @@ -168,13 +168,15 @@ The `initSession()` method automatically also sets an internal deep link hander

```js
onDeviceReady: function() {
Branch.initSession();
},
onResume: function() {
Branch.initSession();
Branch.initSession().then(function (res) {
console.log(res);
alert('Response: ' + JSON.stringify(res));
}).catch(function (err) {
console.error(err);
alert('Error: ' + JSON.stringify(err));
});;;
},
initialize: function() {
document.addEventListener('resume', onResume, false);
document.addEventListener('deviceready', onDeviceReady, false);
},
```
Expand All @@ -183,7 +185,11 @@ Then add the method `DeepLinkHandler()` which will act as our callback when the

```js
function DeepLinkHandler(data) {
alert('Data from initSession: ' + data.data);
if (data) {
alert('Data from deep link: ' + JSON.stringify(data));
} else {
alert('No data found');
}
}
```

Expand Down Expand Up @@ -243,7 +249,11 @@ Logs out the current session, replaces session IDs and identity IDs.

##### Usage
```js
Branch.logout();
Branch.logout().then(function (res) {
console.log(res);
}).catch(function (err) {
console.error(err);
});
```

### <a id="userCompletedAction"></a>userCompletedAction(action[, metaData])
Expand All @@ -258,9 +268,17 @@ Registers custom events.

##### Usage
```js
Branch.userCompletedAction('complete_purchase');
Branch.userCompletedAction('complete_purchase').then(function (res) {
console.log(res);
}).catch(function (err) {
console.error(err);
});

Branch.userCompletedAction('registered', { user: 'Test' });
Branch.userCompletedAction('registered', { user: 'Test' }).then(function (res) {
console.log(res);
}).catch(function (err) {
console.error(err);
});
```
------

Expand Down Expand Up @@ -438,33 +456,33 @@ branchUniversalObj.onShareSheetLaunched(function () {
});
```

###### onShareSheetDismissed
###### onShareSheetDismissed

The event fires when the share sheet is dismissed.
The event fires when the share sheet is dismissed.

```js
branchUniversalObj.onShareSheetDismissed(function () {
console.log('Share sheet dimissed');
});
```
```js
branchUniversalObj.onShareSheetDismissed(function () {
console.log('Share sheet dimissed');
});
```

###### onLinkShareResponse
###### onLinkShareResponse

The event returns a dictionary of the response data.
The event returns a dictionary of the response data.

```js
branchUniversalObj.onLinkShareResponse(function (res) {
console.log('Share link response: ' + JSON.stringify(res));
});
```
```js
branchUniversalObj.onLinkShareResponse(function (res) {
console.log('Share link response: ' + JSON.stringify(res));
});
```

###### onChannelSelected
###### onChannelSelected

The event fires when a channel is selected.
The event fires when a channel is selected.

```js
branchUniversalObj.onChannelSelected(function (res) {
console.log('Channel selected: ' + JSON.stringify(res));
```js
branchUniversalObj.onChannelSelected(function (res) {
console.log('Channel selected: ' + JSON.stringify(res));
});
```

Expand Down
20 changes: 7 additions & 13 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {

Log.d(LCAT, "SessionListener onInitFinished()");

String out = String.format("DeepLinkHandler(%s)", referringParams.toString());

webView.sendJavascript(out);

if (error == null) {

// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
Expand All @@ -798,25 +802,15 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
Log.d(LCAT, "return is not null");
Log.d(LCAT, referringParams.toString());
}

String out = String.format("DeepLinkHandler(%s)", referringParams.toString());

webView.sendJavascript(out);
if (this._callbackContext != null) {
this._callbackContext.success(referringParams);
}

this._callbackContext.success(referringParams);

} else {
String errorMessage = error.getMessage();

Log.d(LCAT, errorMessage);

String out = String.format("DeepLinkHandler(%s)", referringParams.toString());

webView.sendJavascript(out);
if (this._callbackContext != null) {
this._callbackContext.error(errorMessage);
}
this._callbackContext.error(errorMessage);
}

}
Expand Down
5 changes: 1 addition & 4 deletions src/ios/BranchSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@property (copy) NSDictionary *metadata;
@property (copy) NSDate *expirationDate;

@property (strong, nonatomic) BranchUniversalObject *branchUniversalObj;
@property (strong, nonatomic) NSMutableArray *branchUniversalObjArray;

// BranchSDK Basic Methods
- (void)initSession:(CDVInvokedUrlCommand*)command;
Expand All @@ -41,9 +41,6 @@

// Branch Universal Object Methods
- (void)createBranchUniversalObject:(CDVInvokedUrlCommand*)command;
- (void)initWithCanonicalIdentifier:(CDVInvokedUrlCommand*)command;
- (void)initWithTitle:(CDVInvokedUrlCommand*)command;
- (void)addMetadata:(CDVInvokedUrlCommand*)command;
- (void)registerView:(CDVInvokedUrlCommand*)command;
- (void)generateShortUrl:(CDVInvokedUrlCommand*)command;
- (void)showShareSheet:(CDVInvokedUrlCommand*)command;
Expand Down
Loading

0 comments on commit 12c447f

Please sign in to comment.