Skip to content

Commit

Permalink
Merge pull request #262 from BranchMetrics/fix_deeplink_path
Browse files Browse the repository at this point in the history
fix: added $deeplink_path for android
  • Loading branch information
ethanneff authored Dec 15, 2016
2 parents 2e781f4 + 15a7c8a commit c5b6c29
Show file tree
Hide file tree
Showing 23 changed files with 402 additions and 241 deletions.
8 changes: 4 additions & 4 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@ gulp prerelease;
> **[optional]** Update [iOS SDK](https://github.com/BranchMetrics/ios-branch-deep-linking/tags) (will need to update `plugin.xml` dependencies if new iOS files)
```sh
./src/ios/dependencies/update.sh 0.12.14;
./src/ios/dependencies/update.sh 0.12.20;
```

### Test

> Modify `BRANCH_KEY` and `URI_SCHEME` and `config.xml` to values in [Branch Dashboard](https://dashboard.branch.io/settings/link)
```sh
gulp prerelease && cd testbed && npm install -g cordova && cordova platform remove ios && cordova platform remove android && cordova platform remove browser && cordova platform add ios && cordova platform add android && cordova plugin remove io.branch.sdk && cordova plugin add ../ --variable BRANCH_KEY=key_live_icCccJIpd7GlYY5oOmoEtpafuDiuyXhT --variable URI_SCHEME=enefftest;
gulp prerelease; cd testbed; npm install -g cordova; cordova platform remove ios; cordova platform remove android; cordova platform remove browser; cordova platform add ios; cordova platform add android; cordova plugin remove io.branch.sdk; cordova plugin add ../ --variable BRANCH_KEY=key_live_icCccJIpd7GlYY5oOmoEtpafuDiuyXhT --variable URI_SCHEME=enefftest;

# cordova plugin add branch-cordova-sdk --variable BRANCH_KEY=key_live_icCccJIpd7GlYY5oOmoEtpafuDiuyXhT --variable URI_SCHEME=enefftest;
```

> Validate all features on both `iOS` and `Android` on `device` only (no `simulator` or `TestFlight`)
```sh
cordova build ios --developmentTeam="PW4Q8885U7" --device;
cordova build ios && open -a Xcode platforms/ios/Branch\ Testing.xcworkspace;
```

```sh
cordova build android && cordova run android;
cordova build android; cordova run android;
chrome://inspect/#devices
```

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@
- Delete your app from the device *(resets the Apple AASA scraping)*
- Compile your app *(`cordova build ios --developmentTeam="PW4Q8885U7" --device;`)*
- Compile your app *(`cordova build ios` `phone gap build ios` `ionic build ios`)*
- Open the app in Xcode and set your Provisioning Profile `Development Team`
- Open the app in `Xcode` and set your Provisioning Profile `Development Team`
- Launch your app to `device` *(not Simulator or TestFlight)*
Expand All @@ -225,7 +225,7 @@
- Delete your app from the device
- Compile your app *(`cordova run android`)*
- Compile your app *(`cordova build android` `phone gap build android` `ionic build android`)*
- Launch your app to `device` *(not Simulator or Genymotion)*
Expand Down Expand Up @@ -328,6 +328,7 @@
$android_url: 'http://www.example.com/android',
$ios_url: 'http://www.example.com/ios',
$ipad_url: 'http://www.example.com/ipad',
$deeplink_path: "content/123",
more_custom: 'data',
even_more_custom: true,
this_is_custom: 321
Expand Down Expand Up @@ -700,6 +701,8 @@
- Always use the `Branch.initSession(function(data) {});` to read Deep Link data
- Always test on `device` (`simulator` `browser` `genymotion` will break)
- You must launch the app through `Xcode` for iOS
- Other deep link plugins (ex `cordova-universal-links-plugin`) will interferer with Branch
Expand Down
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ SOFTWARE.

<header-file src="src/ios/dependencies/Branch-SDK/BNCCallbacks.h" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCConfig.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCConfig.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.h" />
<source-file src="src/ios/dependencies/Branch-SDK/BNCContentDiscoveryManager.m" />
<header-file src="src/ios/dependencies/Branch-SDK/BNCDeviceInfo.h" />
Expand Down
40 changes: 13 additions & 27 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ private void getFirstReferringParams(CallbackContext callbackContext) {
*/
private void createBranchUniversalObject(JSONObject options, CallbackContext callbackContext) throws JSONException {


BranchUniversalObject branchObj = new BranchUniversalObject();

// Set object properties
Expand All @@ -373,7 +372,6 @@ private void createBranchUniversalObject(JSONObject options, CallbackContext cal

// Set content visibility
if (options.has("contentIndexingMode")) {

if (options.getString("contentIndexingMode").equals("private")) {
branchObj.setContentIndexingMode(BranchUniversalObject.CONTENT_INDEX_MODE.PRIVATE);
} else {
Expand Down Expand Up @@ -447,6 +445,7 @@ private BranchLinkProperties createLinkProperties(JSONObject options, JSONObject

BranchLinkProperties linkProperties = new BranchLinkProperties();

// Add link properties
if (options.has("feature")) {
linkProperties.setFeature(options.getString("feature"));
}
Expand All @@ -465,39 +464,26 @@ private BranchLinkProperties createLinkProperties(JSONObject options, JSONObject
if (options.has("duration")) {
linkProperties.setDuration(options.getInt("duration"));
}

if (options.has("tags")) {
JSONArray array = (JSONArray) options.get("tags");
if (array != null) {
for (int i=0;i<array.length();i++){
for (int i=0; i<array.length(); i++){
linkProperties.addTag(array.get(i).toString());
}
}
}

if (controlParams.has("$fallback_url")) {
linkProperties.addControlParameter("$fallback_url", controlParams.getString("$fallback_url"));
}
if (controlParams.has("$desktop_url")) {
linkProperties.addControlParameter("$desktop_url", controlParams.getString("$desktop_url"));
}
if (controlParams.has("$android_url")) {
linkProperties.addControlParameter("$android_url", controlParams.getString("$android_url"));
}
if (controlParams.has("$ios_url")) {
linkProperties.addControlParameter("$ios_url", controlParams.getString("$ios_url"));
}
if (controlParams.has("$ipad_url")) {
linkProperties.addControlParameter("$ipad_url", controlParams.getString("$ipad_url"));
}
if (controlParams.has("$fire_url")) {
linkProperties.addControlParameter("$fire_url", controlParams.getString("$fire_url"));
}
if (controlParams.has("$blackberry_url")) {
linkProperties.addControlParameter("$blackberry_url", controlParams.getString("$blackberry_url"));
}
if (controlParams.has("$windows_phone_url")) {
linkProperties.addControlParameter("$windows_phone_url", controlParams.getString("$windows_phone_url"));
Log.d(LCAT, "Adding control parameters:");

// Add and iterate control parameters properties
Iterator<?> keys = controlParams.keys();

while (keys.hasNext()) {
String key = keys.next().toString();

Log.d(LCAT, String.format("key: %s", key));

linkProperties.addControlParameter(key, controlParams.getString(key));
}

return linkProperties;
Expand Down
6 changes: 3 additions & 3 deletions src/ios/dependencies/Branch-SDK/BNCCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@class BranchUniversalObject, BranchLinkProperties;

typedef void (^callbackWithParams) (NSDictionary * _Nonnull params, NSError * _Nullable error);
typedef void (^callbackWithUrl) (NSString * _Nonnull url, NSError * _Nullable error);
typedef void (^callbackWithParams) (NSDictionary * _Nullable params, NSError * _Nullable error);
typedef void (^callbackWithUrl) (NSString * _Nullable url, NSError * _Nullable error);
typedef void (^callbackWithStatus) (BOOL changed, NSError * _Nullable error);
typedef void (^callbackWithList) (NSArray * _Nullable list, NSError * _Nullable error);
typedef void (^callbackWithUrlAndSpotlightIdentifier) (NSString * _Nullable url, NSString * _Nullable spotlightIdentifier, NSError * _Nullable error);
typedef void (^callbackWithBranchUniversalObject) (BranchUniversalObject * _Nonnull universalObject, BranchLinkProperties * _Nonnull linkProperties, NSError * _Nullable error);
typedef void (^callbackWithBranchUniversalObject) (BranchUniversalObject * _Nullable universalObject, BranchLinkProperties * _Nullable linkProperties, NSError * _Nullable error);

#endif /* BNCCallbacks_h */
30 changes: 5 additions & 25 deletions src/ios/dependencies/Branch-SDK/BNCConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,9 @@
// Copyright (c) 2014 Branch Metrics. All rights reserved.
//

#ifndef Branch_SDK_Config_h
#define Branch_SDK_Config_h
#import <Foundation/Foundation.h>

#define SDK_VERSION @"0.12.19"

#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.branch.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
extern NSString * const SDK_VERSION;
extern NSString * const BNC_API_BASE_URL;
extern NSString * const BNC_LINK_URL;
extern NSString * const BNC_API_VERSION;
14 changes: 14 additions & 0 deletions src/ios/dependencies/Branch-SDK/BNCConfig.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// BNCConfig.c
// Branch-TestBed
//
// Created by edward on 12/12/16.
// Copyright © 2016 Branch Metrics. All rights reserved.
//

#include "BNCConfig.h"

NSString * const BNC_API_BASE_URL = @"https://api.branch.io";
NSString * const BNC_API_VERSION = @"v1";
NSString * const BNC_LINK_URL = @"https://bnc.lt";
NSString * const SDK_VERSION = @"0.12.20";
21 changes: 16 additions & 5 deletions src/ios/dependencies/Branch-SDK/BNCDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (id)init {
self.isRealHardwareId = isRealHardwareId;
self.hardwareIdType = hardwareIdType;
}

self.vendorId = [BNCSystemObserver getVendorId];
self.brandName = [BNCSystemObserver getBrand];
self.modelName = [BNCSystemObserver getModel];
Expand Down Expand Up @@ -83,10 +83,21 @@ - (id)init {

}

self.browserUserAgent =
[[[UIWebView alloc]
initWithFrame:CGRectZero]
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
void (^setUpBrowserUserAgent)() = ^() {
self.browserUserAgent = [[[UIWebView alloc]
initWithFrame:CGRectZero]
stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
};

if (NSThread.isMainThread) {

setUpBrowserUserAgent();

} else {

dispatch_sync(dispatch_get_main_queue(), setUpBrowserUserAgent);

}

return self;
}
Expand Down
89 changes: 52 additions & 37 deletions src/ios/dependencies/Branch-SDK/BNCPreferenceHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,20 @@ - (void)setUniversalLinkUrl:(NSString *)universalLinkUrl {
}

- (NSString *)sessionParams {
if (_sessionParams) {
_sessionParams = [self readStringFromDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS];
@synchronized (self) {
if (!_sessionParams) {
_sessionParams = [self readStringFromDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS];
}
return _sessionParams;
}

return _sessionParams;
}

- (void)setSessionParams:(NSString *)sessionParams {
if (![_sessionParams isEqualToString:sessionParams]) {
_sessionParams = sessionParams;
[self writeObjectToDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS value:sessionParams];
@synchronized (self) {
if (![_sessionParams isEqualToString:sessionParams]) {
_sessionParams = sessionParams;
[self writeObjectToDefaults:BRANCH_PREFS_KEY_SESSION_PARAMS value:sessionParams];
}
}
}

Expand Down Expand Up @@ -479,22 +482,28 @@ - (void)setRequestMetadataKey:(NSString *)key value:(NSObject *)value {
}

- (NSMutableDictionary *)instrumentationDictionary {
if (!_instrumentationDictionary) {
_instrumentationDictionary = [NSMutableDictionary dictionary];
@synchronized (self) {
if (!_instrumentationDictionary) {
_instrumentationDictionary = [NSMutableDictionary dictionary];
}
return _instrumentationDictionary;
}
return _instrumentationDictionary;
}

- (void)addInstrumentationDictionaryKey:(NSString *)key value:(NSString *)value {
if (key && value) {
[self.instrumentationDictionary setObject:value forKey:key];
@synchronized (self) {
if (key && value) {
[self.instrumentationDictionary setObject:value forKey:key];
}
}
}

- (void)clearInstrumentationDictionary {
NSArray *keys = [_instrumentationDictionary allKeys];
for (int i = 0 ; i < [keys count]; i++) {
[_instrumentationDictionary removeObjectForKey:keys[i]];
@synchronized (self) {
NSArray *keys = [_instrumentationDictionary allKeys];
for (int i = 0 ; i < [keys count]; i++) {
[_instrumentationDictionary removeObjectForKey:keys[i]];
}
}
}

Expand Down Expand Up @@ -606,42 +615,48 @@ - (NSDictionary *)getContentAnalyticsManifest {
return (NSDictionary *)[self readObjectFromDefaults:BRANCH_PREFS_KEY_ANALYTICS_MANIFEST];
}


#pragma mark - Writing To Persistence


- (void)writeIntegerToDefaults:(NSString *)key value:(NSInteger)value {
self.persistenceDict[key] = @(value);
[self persistPrefsToDisk];
[self writeObjectToDefaults:key value:@(value)];
}

- (void)writeBoolToDefaults:(NSString *)key value:(BOOL)value {
self.persistenceDict[key] = @(value);
[self persistPrefsToDisk];
[self writeObjectToDefaults:key value:@(value)];
}

- (void)writeObjectToDefaults:(NSString *)key value:(NSObject *)value {
if (value) {
self.persistenceDict[key] = value;
}
else {
[self.persistenceDict removeObjectForKey:key];
@synchronized (self) {
if (value) {
self.persistenceDict[key] = value;
}
else {
[self.persistenceDict removeObjectForKey:key];
}
[self persistPrefsToDisk];
}

[self persistPrefsToDisk];
}

- (void)persistPrefsToDisk {
@synchronized (self) {
NSDictionary *persistenceDict = [self.persistenceDict copy];
if (!self.persistenceDict) return;
NSData *data = nil;
@try {
data = [NSKeyedArchiver archivedDataWithRootObject:self.persistenceDict];
}
@catch (id exception) {
data = nil;
[self logWarning:
[NSString stringWithFormat:@"Exception creating preferences data: %@.",
exception]];
}
if (!data) {
[self logWarning:@"Can't create preferences data."];
return;
}
NSBlockOperation *newPersistOp = [NSBlockOperation blockOperationWithBlock:^ {
NSData *data = nil;
@try {
data = [NSKeyedArchiver archivedDataWithRootObject:persistenceDict];
} @catch (id n) {
}
if (!data) {
[self logWarning:@"Can't create preferences archive."];
return;
}
NSError *error = nil;
[data writeToURL:self.class.URLForPrefsFile
options:NSDataWritingAtomic error:&error];
Expand All @@ -651,7 +666,7 @@ - (void)persistPrefsToDisk {
@"Failed to persist preferences to disk: %@.", error]];
}
}];
[self.persistPrefsQueue addOperation:newPersistOp];
[self.persistPrefsQueue addOperation:newPersistOp];
}
}

Expand Down
Loading

0 comments on commit c5b6c29

Please sign in to comment.