Skip to content

Commit

Permalink
Updated ios source. Added basic implementation of plugin and initSess…
Browse files Browse the repository at this point in the history
…ion method
  • Loading branch information
jestoniyap committed Jan 18, 2016
1 parent 6b6e246 commit 5ecc2fc
Show file tree
Hide file tree
Showing 21 changed files with 1,980 additions and 7 deletions.
12 changes: 5 additions & 7 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ SOFTWARE.
<param name="ios-package" value="BranchSDK" />
</feature>
</config-file>
<config-file target="*-Info.plist" parent="CFBundleURLTypes">
<array>
<dict>
<key>branch_key</key>
<string>key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv</string>
</dict>
</array>
<config-file target="*-Info.plist" parent="branch_key">
<dict>
<key>live</key>
<string>key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv</string>
</dict>
</config-file>
<header-file src="src/ios/BranchSDK.h" />
<source-file src="src/ios/BranchSDK.m" />
Expand Down
15 changes: 15 additions & 0 deletions src/ios/BranchSDK.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// BranchSDK.h
// Branch-TestBed
//
// Created by Lysis on 1/14/16.
// Copyright © 2016 Branch Metrics. All rights reserved.
//

#import <Cordova/CDV.h>

@interface BranchSDK : CDVPlugin

- (void)initSession:(CDVInvokedUrlCommand*)command;

@end
86 changes: 86 additions & 0 deletions src/ios/BranchSDK.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// BranchSDK.m
// Branch-TestBed
//
// Created by Lysis on 1/14/16.
// Copyright © 2016 Branch Metrics. All rights reserved.
//

#import "BranchSDK.h"
#import <Branch/Branch.h>
#import <Cordova/CDV.h>

@implementation BranchSDK

#pragma mark - Private APIs
#pragma mark - Global Instance Accessors

- (Branch *)getInstance
{
NSLog(@"start getInstance");
return [Branch getInstance];
}

- (Branch *)getInstance:(NSString *)branchKey
{
NSLog(@"start getInstance with branchKey");
if (branchKey) {
return [Branch getInstance:branchKey];
}
else {
return [Branch getInstance];
}
}

- (Branch *)getTestInstance
{
NSLog(@"start getTestInstance");
return [Branch getTestInstance];
}

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

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

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

[branch initSessionAndRegisterDeepLinkHandler:^(NSDictionary *params, NSError *error) {
NSLog(@"inside initSessionAndRegisterDeepLinkHandler");
CDVPluginResult* pluginResult = nil;
if (!error) {
if (params != nil && [params count] > 0) {
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"];
}
}
else {
NSLog(@"Init Error: %@", [error localizedDescription]);
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:[error localizedDescription]];
}
NSLog(@"returning data to js interface..");
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

@end
1 change: 1 addition & 0 deletions src/ios/dependencies/Branch.framework/Branch
1 change: 1 addition & 0 deletions src/ios/dependencies/Branch.framework/Headers
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// BNCConfig.h
// Branch-SDK
//
// Created by Qinwei Gong on 10/6/14.
// Copyright (c) 2014 Branch Metrics. All rights reserved.
//

#ifndef Branch_SDK_Config_h
#define Branch_SDK_Config_h

#define SDK_VERSION @"0.11.14"

#define BNC_PROD_ENV
//#define BNC_STAGE_ENV
//#define BNC_DEV_ENV

#ifdef BNC_PROD_ENV
#define BNC_API_BASE_URL @"https://api.branch.io"
#endif

#ifdef BNC_STAGE_ENV
#define BNC_API_BASE_URL @"http://api.dev.branchmetrics.io"
#endif

#define BNC_LINK_URL @"https://bnc.lt"

#ifdef BNC_DEV_ENV
#define BNC_API_BASE_URL @"http://localhost:3001"
#endif

#define BNC_API_VERSION @"v1"

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// BNCLinkCache.h
// Branch-SDK
//
// Created by Qinwei Gong on 1/23/15.
// Copyright (c) 2015 Branch Metrics. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BNCLinkData.h"

@interface BNCLinkCache : NSObject

- (void)setObject:(NSString *)anObject forKey:(BNCLinkData *)aKey;
- (NSString *)objectForKey:(BNCLinkData *)aKey;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// BNCLinkData.h
// Branch-SDK
//
// Created by Qinwei Gong on 1/22/15.
// Copyright (c) 2015 Branch Metrics. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, BranchLinkType) {
BranchLinkTypeUnlimitedUse = 0,
BranchLinkTypeOneTimeUse = 1
};

@interface BNCLinkData : NSObject

@property (strong, nonatomic) NSMutableDictionary *data;

- (void)setupTags:(NSArray *)tags;
- (void)setupAlias:(NSString *)alias;
- (void)setupType:(BranchLinkType)type;
- (void)setupChannel:(NSString *)channel;
- (void)setupFeature:(NSString *)feature;
- (void)setupStage:(NSString *)stage;
- (void)setupParams:(NSDictionary *)params;
- (void)setupMatchDuration:(NSUInteger)duration;
- (void)setupIgnoreUAString:(NSString *)ignoreUAString;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// BNCPreferenceHelper.h
// Branch-SDK
//
// Created by Alex Austin on 6/6/14.
// Copyright (c) 2014 Branch Metrics. All rights reserved.
//

#import <Foundation/Foundation.h>

#define FILE_NAME [[NSString stringWithUTF8String:__FILE__] lastPathComponent]
#define LINE_NUM __LINE__

@interface BNCPreferenceHelper : NSObject

@property (strong, nonatomic) NSString *branchKey;
@property (strong, nonatomic) NSString *appKey;
@property (strong, nonatomic) NSString *lastRunBranchKey;
@property (strong, nonatomic) NSDate *lastStrongMatchDate;
@property (strong, nonatomic) NSString *appVersion;
@property (strong, nonatomic) NSString *deviceFingerprintID;
@property (strong, nonatomic) NSString *sessionID;
@property (strong, nonatomic) NSString *identityID;
@property (strong, nonatomic) NSString *linkClickIdentifier;
@property (strong, nonatomic) NSString *spotlightIdentifier;
@property (strong, nonatomic) NSString *universalLinkUrl;
@property (strong, nonatomic) NSString *userUrl;
@property (strong, nonatomic) NSString *userIdentity;
@property (strong, nonatomic) NSString *sessionParams;
@property (strong, nonatomic) NSString *installParams;
@property (assign, nonatomic) BOOL explicitlyRequestedReferrable;
@property (assign, nonatomic) BOOL isReferrable;
@property (assign, nonatomic) BOOL isDebug;
@property (assign, nonatomic) BOOL isContinuingUserActivity;
@property (assign, nonatomic) NSInteger retryCount;
@property (assign, nonatomic) NSTimeInterval retryInterval;
@property (assign, nonatomic) NSTimeInterval timeout;
@property (strong, nonatomic) NSString *externalIntentURI;

+ (BNCPreferenceHelper *)preferenceHelper;

- (NSString *)getAPIBaseURL;
- (NSString *)getAPIURL:(NSString *)endpoint;
- (NSString *)getBranchKey:(BOOL)isLive;

- (void)clearUserCreditsAndCounts;
- (void)clearUserCredits;

- (id)getBranchUniversalLinkDomains;

- (void)setCreditCount:(NSInteger)count;
- (void)setCreditCount:(NSInteger)count forBucket:(NSString *)bucket;
- (void)removeCreditCountForBucket:(NSString *)bucket;
- (NSDictionary *)getCreditDictionary;
- (NSInteger)getCreditCount;
- (NSInteger)getCreditCountForBucket:(NSString *)bucket;

- (void)setActionTotalCount:(NSString *)action withCount:(NSInteger)count;
- (void)setActionUniqueCount:(NSString *)action withCount:(NSInteger)count;
- (NSInteger)getActionTotalCount:(NSString *)action;
- (NSInteger)getActionUniqueCount:(NSString *)action;

- (void)log:(NSString *)filename line:(int)line message:(NSString *)format, ...;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// BNCServerInterface.h
// Branch-SDK
//
// Created by Alex Austin on 6/4/14.
// Copyright (c) 2014 Branch Metrics. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BNCServerResponse.h"
#import "BNCPreferenceHelper.h"

typedef void (^BNCServerCallback)(BNCServerResponse *response, NSError *error);

static NSString *REQ_TAG_DEBUG_CONNECT = @"t_debug_connect";
static NSString *REQ_TAG_DEBUG_LOG = @"t_debug_log";
static NSString *REQ_TAG_DEBUG_SCREEN = @"t_debug_screen";
static NSString *REQ_TAG_DEBUG_DISCONNECT = @"t_debug_disconnect";

@interface BNCServerInterface : NSObject

@property (strong, nonatomic) BNCPreferenceHelper *preferenceHelper;

- (BNCServerResponse *)getRequest:(NSDictionary *)params url:(NSString *)url key:(NSString *)key;
- (BNCServerResponse *)getRequest:(NSDictionary *)params url:(NSString *)url key:(NSString *)key log:(BOOL)log;
- (void)getRequest:(NSDictionary *)params url:(NSString *)url key:(NSString *)key callback:(BNCServerCallback)callback;
- (void)getRequest:(NSDictionary *)params url:(NSString *)url key:(NSString *)key log:(BOOL)log callback:(BNCServerCallback)callback;

- (BNCServerResponse *)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key log:(BOOL)log;
- (void)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key callback:(BNCServerCallback)callback;
- (void)postRequest:(NSDictionary *)post url:(NSString *)url key:(NSString *)key log:(BOOL)log callback:(BNCServerCallback)callback;

- (void)genericHTTPRequest:(NSURLRequest *)request log:(BOOL)log callback:(BNCServerCallback)callback;
- (BNCServerResponse *)genericHTTPRequest:(NSURLRequest *)request log:(BOOL)log;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// BNCServerRequest.h
// Branch-SDK
//
// Created by Alex Austin on 6/5/14.
// Copyright (c) 2014 Branch Metrics. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BNCServerInterface.h"

@interface BNCServerRequest : NSObject <NSCoding>

- (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback;
- (void)processResponse:(BNCServerResponse *)response error:(NSError *)error;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// BNCServerRequestQueue.h
// Branch-SDK
//
// Created by Qinwei Gong on 9/6/14.
//
//

#import "BNCServerRequest.h"

@class BranchOpenRequest;

@interface BNCServerRequestQueue : NSObject

@property (nonatomic, readonly) unsigned int size;

- (void)enqueue:(BNCServerRequest *)request;
- (BNCServerRequest *)dequeue;
- (BNCServerRequest *)peek;
- (BNCServerRequest *)peekAt:(unsigned int)index;
- (void)insert:(BNCServerRequest *)request at:(unsigned int)index;
- (BNCServerRequest *)removeAt:(unsigned int)index;
- (void)remove:(BNCServerRequest *)request;
- (void)persistEventually;
- (void)persistImmediately;
- (void)clearQueue;

- (BOOL)containsInstallOrOpen;
- (BOOL)containsClose;
- (BranchOpenRequest *)moveInstallOrOpenToFront:(NSInteger)networkCount;

+ (id)getInstance;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BNCServerResponse.h
// Branch-SDK
//
// Created by Qinwei Gong on 10/10/14.
// Copyright (c) 2014 Branch Metrics. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface BNCServerResponse : NSObject

@property (nonatomic, strong) NSNumber *statusCode;
@property (nonatomic, strong) id data;

@end
Loading

0 comments on commit 5ecc2fc

Please sign in to comment.