Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sarkar committed Mar 25, 2016
2 parents df1f0a1 + 7ea01ee commit ecff54d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 74 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ There's a full demo app embedded in this repository. It should serve as an examp

**Latest libraries for [Android](http://developer.android.com/sdk/index.html) and/or iOS SDKs must be installed.**

### Command link install
### Command line install

**Install parameters:**
* `BRANCH_KEY` - Your Branch live API key. You can sign up for your own Branch key at [https://dashboard.branch.io](https://dashboard.branch.io).
Expand Down Expand Up @@ -439,29 +439,29 @@ branchUniversalObj.onShareSheetLaunched(function () {
```

###### onShareSheetDismissed

The event fires when the share sheet is dismissed.

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

###### onLinkShareResponse

The event returns a dictionary of the response data.

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

###### onChannelSelected

The event fires when a channel is selected.

```js
branchUniversalObj.onChannelSelected(function (res) {
console.log('Channel selected: ' + JSON.stringify(res));
Expand Down
16 changes: 9 additions & 7 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ public BranchSDK()
public void onNewIntent(Intent intent)
{
Log.d(LCAT, "start onNewIntent()");

this.activity = this.cordova.getActivity();
this.activity.setIntent(intent);

if (this.activity != null) {
this.setDebug(true);
this.initSession(null);
}
}
Expand Down Expand Up @@ -343,15 +345,15 @@ private void getLatestReferringParams(CallbackContext callbackContext)

JSONObject sessionParams = this.instance.getLatestReferringParams();

if (sessionParams == null) {
if (sessionParams == null || sessionParams.length() == 0) {
Log.d(LCAT, "return is null");
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, /* send boolean: false as the data */ false));
} else {
Log.d(LCAT, "return is not null");
Log.d(LCAT, sessionParams.toString());
callbackContext.success(sessionParams);
}

callbackContext.success(sessionParams);

}

/**
Expand All @@ -370,15 +372,15 @@ private void getFirstReferringParams(CallbackContext callbackContext)

JSONObject installParams = this.instance.getFirstReferringParams();

if (installParams == null) {
if (installParams == null || installParams.length() == 0) {
Log.d(LCAT, "return is null");
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, /* send boolean: false as the data */ false));
} else {
Log.d(LCAT, "return is not null");
Log.d(LCAT, installParams.toString());
callbackContext.success(installParams);
}

callbackContext.success(installParams);

}

/**
Expand Down
97 changes: 39 additions & 58 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
[branch initSessionWithLaunchOptions:nil andRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
NSLog(@"inside initSessionAndRegisterDeepLinkHandler block");
NSString *resultString;
CDVPluginResult *pluginResult = nil;
if (!error) {
if (params != nil && [params count] > 0) {
NSError *err;
Expand All @@ -83,13 +84,16 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
resultString = [NSString stringWithFormat:@"Parsing Error: %@", [err localizedDescription]];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:resultString];
} else {
NSLog(@"Success");
resultString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
}
} else {
NSLog(@"No data found");
resultString = @"No data found";
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:resultString];
}
}
else {
Expand All @@ -102,8 +106,15 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
error:&error];

resultString = [[NSString alloc] initWithData:errorJSON encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:resultString];
}
NSLog(@"returning data to js interface..");
if (command != nil) {
NSLog(@"Sending to JS: %@", [params description]);
[self.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId];
} else {
NSLog(@"Command is nil");
}
[self.commandDelegate evalJs:[NSString stringWithFormat:@"DeepLinkHandler(%@)", resultString]];
}];
}
Expand All @@ -129,21 +140,11 @@ - (void)getLatestReferringParams:(CDVInvokedUrlCommand*)command
CDVPluginResult* pluginResult = nil;

if (sessionParams != nil && [sessionParams count] > 0) {
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:sessionParams
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
}
NSLog(@"Success");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:sessionParams];
} else {
NSLog(@"No data found");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Empty data"];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:FALSE];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand All @@ -158,21 +159,11 @@ - (void)getFirstReferringParams:(CDVInvokedUrlCommand*)command
CDVPluginResult* pluginResult = nil;

if (installParams != nil && [installParams count] > 0) {
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:installParams
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
}
NSLog(@"Success");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:installParams];
} else {
NSLog(@"No data found");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Empty data"];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:FALSE];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand Down Expand Up @@ -239,13 +230,25 @@ - (void)userCompletedAction:(CDVInvokedUrlCommand*)command
else {
[branch userCompletedAction:name];
}

// TODO: need to resolve according to result of userCompletedAction, but no callback version of the method is exposed.
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"Success"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)logout:(CDVInvokedUrlCommand*)command
{
NSLog(@"start logout");
Branch *branch = [self getInstance];
[branch logout];
[branch logoutWithCallback:^(BOOL changed, NSError *error) {
CDVPluginResult *pluginResult = nil;
if (!error) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Success"];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
self.branchUniversalObj = nil;
}

Expand All @@ -260,19 +263,9 @@ - (void)loadRewards:(CDVInvokedUrlCommand*)command
NSLog(@"inside loadRewardsWithCallback block");
CDVPluginResult* pluginResult = nil;
if(!error) {
NSNumber *credits = [NSNumber numberWithInteger:[branch getCredits]];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"credits":credits}
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
}
int credits = (int)[branch getCredits];
NSLog(@"Success");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:credits];
}
else {
NSLog(@"Load Rewards Error: %@", [error localizedDescription]);
Expand Down Expand Up @@ -359,18 +352,8 @@ - (void)getCreditHistory:(CDVInvokedUrlCommand*)command
NSLog(@"inside getCreditHistoryWithCallback block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:list
options:0
error:&err];
if (!jsonData) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
}
NSLog(@"Success");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsArray:list];
}
else {
NSLog(@"Credit History Error: %@", [error localizedDescription]);
Expand Down Expand Up @@ -494,16 +477,14 @@ - (void)generateShortUrl:(CDVInvokedUrlCommand*)command
CDVPluginResult* pluginResult = nil;
if (!error) {
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"generatedLink":url}
options:0
error:&err];
if (!jsonData) {
NSDictionary *jsonObj = [[NSDictionary alloc] initWithObjectsAndKeys:url, @"url", 0, @"options", &err, @"error", nil];

if (!jsonObj) {
NSLog(@"Parsing Error: %@", [err localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[err localizedDescription]];
} else {
NSLog(@"Success");
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:jsonString];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj];
}
}
else {
Expand Down

0 comments on commit ecff54d

Please sign in to comment.