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 committed Jan 20, 2016
2 parents 58d7497 + fb43cee commit a6daa97
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/ios/BranchSDK.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,13 @@
@interface BranchSDK : CDVPlugin

- (void)initSession:(CDVInvokedUrlCommand*)command;
- (void)setDebug:(CDVInvokedUrlCommand*)command;
- (void)getAutoInstance:(CDVInvokedUrlCommand*)command;
- (void)getLatestReferringParams:(CDVInvokedUrlCommand*)command;
- (void)getFirstReferringParams:(CDVInvokedUrlCommand*)command;
- (void)setIdentity:(CDVInvokedUrlCommand*)command;
- (void)registerDeepLinkController:(CDVInvokedUrlCommand*)command;
- (void)userCompletedAction:(CDVInvokedUrlCommand*)command;
- (void)logout:(CDVInvokedUrlCommand*)command;

@end
147 changes: 140 additions & 7 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ - (Branch *)getTestInstance
return [Branch getTestInstance];
}

- (void)setDebug:(id)args
{
NSLog(@"start setDebug");
[[Branch getInstance] setDebug];
}

#pragma mark Public APIs
#pragma mark - InitSession Permutation methods

Expand All @@ -53,7 +47,7 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
Branch *branch = [self getInstance];

[branch initSessionAndRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
NSLog(@"inside initSessionAndRegisterDeepLinkHandler");
NSLog(@"inside initSessionAndRegisterDeepLinkHandler block");
CDVPluginResult* pluginResult = nil;
if (!error) {
if (params != nil && [params count] > 0) {
Expand Down Expand Up @@ -83,4 +77,143 @@ - (void)initSession:(CDVInvokedUrlCommand*)command
}];
}

- (void)setDebug:(CDVInvokedUrlCommand*)command
{
NSLog(@"start setDebug");
[[Branch getInstance] setDebug];
}

- (void)getAutoInstance:(CDVInvokedUrlCommand*)command
{
NSLog(@"start setDebug");
[self initSession:nil];
}

- (void)getLatestReferringParams:(CDVInvokedUrlCommand*)command
{
NSLog(@"start getLatestReferringParams");
Branch *branch = [self getInstance];
NSDictionary *sessionParams = [branch getLatestReferringParams];

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];
}
} else {
NSLog(@"No data found");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Empty data"];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)getFirstReferringParams:(CDVInvokedUrlCommand*)command
{
NSLog(@"start getFirstReferringParams");
Branch *branch = [self getInstance];
NSDictionary *installParams = [branch getFirstReferringParams];

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];
}
} else {
NSLog(@"No data found");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Empty data"];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)setIdentity:(CDVInvokedUrlCommand*)command
{
NSLog(@"start setIdentity");
Branch *branch = [self getInstance];

[branch setIdentity:[command.arguments objectAtIndex:0] withCallback:^(NSDictionary *params, NSError *error) {
NSLog(@"inside setIdentity block");
CDVPluginResult* pluginResult = nil;
if (!error) {
NSError *err;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params
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(@"No data found");
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Empty data"];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

- (void)registerDeepLinkController:(CDVInvokedUrlCommand*)command
{
NSLog(@"start registerDeepLinkController");
UIViewController<BranchDeepLinkingController> *controller = (UIViewController<BranchDeepLinkingController>*)self.viewController;
Branch *branch = [self getInstance];
[branch registerDeepLinkController:controller forKey:[command.arguments objectAtIndex:0]];
}

- (void)userCompletedAction:(CDVInvokedUrlCommand*)command
{
NSString *name;
NSDictionary *state;
// if a state dictionary is passed as an argument
if ([command.arguments count] == 2) {
name = [command.arguments objectAtIndex:0];
state = [command.arguments objectAtIndex:1];
}
else {
name = (NSString *)command.arguments;
}

Branch *branch = [self getInstance];

if (state) {
[branch userCompletedAction:name withState:state];
}
else {
[branch userCompletedAction:name];
}
}

- (void)logout:(CDVInvokedUrlCommand*)command
{
NSLog(@"start logout");
Branch *branch = [self getInstance];
[branch logout];
}

@end

0 comments on commit a6daa97

Please sign in to comment.