Skip to content

Commit

Permalink
Merge branch 'project-restructure' of github.com:BranchMetrics/Cordov…
Browse files Browse the repository at this point in the history
…a-Ionic-PhoneGap-Deferred-Deep-Linking-SDK into project-restructure
  • Loading branch information
Renemari Padillo authored and Renemari Padillo committed Mar 1, 2016
2 parents 6377f1f + 9cfe039 commit c8803c2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,14 @@ Redeems a reward with the given amount/value.

**Parameters**

**value**: `int` - Amount to be redeemed.
| KEY | TYPE | MEANING
| -------- | -------- |------------------------
| value | `int` | Amount to be redeemed.
| bucket | `int` | Bucket where the amount will be redeemed. _optional_

##### Usage
```js
Branch.redeemRewards(100).then(function (res) {
Branch.redeemRewards(100, "default").then(function (res) {
// Success Callback
console.log(res);
}).catch(function (err) {
Expand Down
82 changes: 58 additions & 24 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,68 @@ - (void)loadRewards:(CDVInvokedUrlCommand*)command
- (void)redeemRewards:(CDVInvokedUrlCommand*)command
{
NSLog(@"start redeemRewards");

NSInteger amount = ((NSNumber *)[command.arguments objectAtIndex:0]).integerValue;
Branch *branch = [self getInstance];

[branch redeemRewards:amount callback:^(BOOL changed, NSError *error) {
NSLog(@"inside redeemRewards block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSNumber *changedValue = [NSNumber numberWithBool:changed];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"changed":changedValue}
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];
if ([command.arguments count] == 2) {

NSString *bucket = [command.arguments objectAtIndex:1];

[branch redeemRewards:(NSInteger)amount forBucket:(NSString *)bucket callback:^(BOOL changed, NSError *error) {
NSLog(@"inside redeemRewards:forBucket block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSNumber *changedValue = [NSNumber numberWithBool:changed];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"changed":changedValue}
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];
}
}
}
else {
NSLog(@"Redeem Rewards Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
else {
NSLog(@"Redeem Rewards Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
} else {
[branch redeemRewards:amount callback:^(BOOL changed, NSError *error) {
NSLog(@"inside redeemRewards block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSNumber *changedValue = [NSNumber numberWithBool:changed];
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:@{@"changed":changedValue}
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];
}
}
else {
NSLog(@"Redeem Rewards Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}


}

- (void)getCreditHistory:(CDVInvokedUrlCommand*)command
Expand Down

0 comments on commit c8803c2

Please sign in to comment.