From 770a74d09d6e34ba37c7be0d5b5794494c0bc778 Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Sun, 19 Jun 2016 22:28:22 -0700 Subject: [PATCH 1/6] Fix iOS non deep link handler --- src/ios/BranchSDK.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ios/BranchSDK.m b/src/ios/BranchSDK.m index 53ada2dc..b4c05dc0 100644 --- a/src/ios/BranchSDK.m +++ b/src/ios/BranchSDK.m @@ -9,6 +9,8 @@ @interface BranchSDK() +@property (strong, nonatomic) NSString *deepLinkUrl; + - (void)doShareLinkResponse:(int)callbackId sendResponse:(NSDictionary*)response; @end @@ -51,6 +53,7 @@ - (id)handleDeepLink:(CDVInvokedUrlCommand*)command { NSString *arg = [command.arguments objectAtIndex:0]; NSURL *url = [NSURL URLWithString:arg]; + self.deepLinkUrl = [url absoluteString]; Branch *branch = [self getInstance]; return [NSNumber numberWithBool:[branch handleDeepLink:url]]; @@ -65,6 +68,10 @@ - (void)continueUserActivity:(CDVInvokedUrlCommand*)command NSUserActivity *userActivity = [[NSUserActivity alloc] initWithActivityType:activityType]; [userActivity setUserInfo:userInfo]; + if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) { + self.deepLinkUrl = [userActivity.webpageURL absoluteString]; + } + Branch *branch = [self getInstance]; [branch continueUserActivity:userActivity]; @@ -125,6 +132,10 @@ - (void)initSession:(CDVInvokedUrlCommand*)command if (isFromBranchLink) { [self.commandDelegate evalJs:[NSString stringWithFormat:@"DeepLinkHandler(%@)", resultString]]; } + else if (self.deepLinkUrl) { + [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"BSDKPostUnhandledURL" object:self.deepLinkUrl]]; + self.deepLinkUrl = nil; + } if (command != nil) { [self.commandDelegate sendPluginResult: pluginResult callbackId: command.callbackId]; From fba5bc2c0597493f8ac5278325f39422bf2acae8 Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Mon, 20 Jun 2016 11:03:55 -0700 Subject: [PATCH 2/6] make Android work the same --- src/android/io/branch/BranchSDK.java | 24 +++++++++++++++++++----- src/ios/BranchSDK.m | 2 +- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index d129b123..15007526 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Iterator; +import android.net.Uri; import io.branch.indexing.BranchUniversalObject; import io.branch.referral.Branch; @@ -33,6 +34,7 @@ static class BranchLinkProperties extends io.branch.referral.util.LinkProperties private ArrayList branchObjectWrappers; private Activity activity; private Branch instance; + private String deepLinkUrl; /** * Class Constructor @@ -221,9 +223,14 @@ private void initSession(CallbackContext callbackContext) { this.activity = this.cordova.getActivity(); + Uri data = activity.getIntent().getData(); + if (data != null && data.isHierarchical()) { + this.deepLinkUrl = data.toString(); + } + this.instance = Branch.getAutoInstance(this.activity.getApplicationContext()); - this.instance.initSession(new SessionListener(callbackContext), activity.getIntent().getData(), activity); + this.instance.initSession(new SessionListener(callbackContext), data, activity); } /** @@ -710,10 +717,17 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { this._callbackContext.success(referringParams); } - } else { - String errorMessage = error.getMessage(); - - out = String.format("NonBranchLinkHandler(\"%s\")", error.toString()); + } else if (self.deepLinkUrl != null) { + JSONObject message = new JSONObject(); + try { + params.put("error", "Not a Branch link!"); + params.put("url", self.deepLinkUrl); + self.deepLinkUrl = null; + } catch (JSONException e) { + e.printStackTrace(); + } + + out = String.format("NonBranchLinkHandler(\"%s\")", message.toString()); webView.sendJavascript(out); if (this._callbackContext != null) { diff --git a/src/ios/BranchSDK.m b/src/ios/BranchSDK.m index b4c05dc0..177058ad 100644 --- a/src/ios/BranchSDK.m +++ b/src/ios/BranchSDK.m @@ -601,7 +601,7 @@ - (void)postUnhandledURL:(NSNotification *)notification { } if ([urlString isKindOfClass:[NSString class]]) { - NSDictionary *returnDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Unable to process URL", @"error", urlString, @"url", nil]; + NSDictionary *returnDict = [NSDictionary dictionaryWithObjectsAndKeys:@"Not a Branch link!", @"error", urlString, @"url", nil]; NSData* returnJSON = [NSJSONSerialization dataWithJSONObject:returnDict options:NSJSONWritingPrettyPrinted error:&error]; From dbcc07bc0d71ab67a57ef72ba5547fdbb89601d8 Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Fri, 24 Jun 2016 18:01:04 -0700 Subject: [PATCH 3/6] update android reference --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 80121f1b..b5a07176 100644 --- a/plugin.xml +++ b/plugin.xml @@ -75,7 +75,7 @@ SOFTWARE. - + From 030aa58cc9d8721fbdbe08f674a15ad6c80ae7fd Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Fri, 24 Jun 2016 18:18:13 -0700 Subject: [PATCH 4/6] bad syntax --- src/android/io/branch/BranchSDK.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index 15007526..6649fc47 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -717,12 +717,12 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { this._callbackContext.success(referringParams); } - } else if (self.deepLinkUrl != null) { + } else if (this.deepLinkUrl != null) { JSONObject message = new JSONObject(); try { params.put("error", "Not a Branch link!"); - params.put("url", self.deepLinkUrl); - self.deepLinkUrl = null; + params.put("url", this.deepLinkUrl); + this.deepLinkUrl = null; } catch (JSONException e) { e.printStackTrace(); } From 845b1a9580e79f834b8ddfd3a75f64a5487146fb Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Fri, 24 Jun 2016 18:19:40 -0700 Subject: [PATCH 5/6] wrong parent --- src/android/io/branch/BranchSDK.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index 6649fc47..87159a5e 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -717,12 +717,12 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { this._callbackContext.success(referringParams); } - } else if (this.deepLinkUrl != null) { + } else if (deepLinkUrl != null) { JSONObject message = new JSONObject(); try { params.put("error", "Not a Branch link!"); - params.put("url", this.deepLinkUrl); - this.deepLinkUrl = null; + params.put("url", deepLinkUrl); + deepLinkUrl = null; } catch (JSONException e) { e.printStackTrace(); } From 3c305ad0b89f3e25472feb31ff39b8b1b3d509c4 Mon Sep 17 00:00:00 2001 From: Alex Austin Date: Fri, 24 Jun 2016 18:21:14 -0700 Subject: [PATCH 6/6] ugh --- src/android/io/branch/BranchSDK.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/android/io/branch/BranchSDK.java b/src/android/io/branch/BranchSDK.java index 87159a5e..2df86e60 100644 --- a/src/android/io/branch/BranchSDK.java +++ b/src/android/io/branch/BranchSDK.java @@ -720,8 +720,8 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { } else if (deepLinkUrl != null) { JSONObject message = new JSONObject(); try { - params.put("error", "Not a Branch link!"); - params.put("url", deepLinkUrl); + message.put("error", "Not a Branch link!"); + message.put("url", deepLinkUrl); deepLinkUrl = null; } catch (JSONException e) { e.printStackTrace(); @@ -731,7 +731,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { webView.sendJavascript(out); if (this._callbackContext != null) { - this._callbackContext.error(errorMessage); + this._callbackContext.error(message); } }