From c785782836a9bf0ece5f289873816325e168f5d9 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Tue, 28 Feb 2023 15:37:57 -0800 Subject: [PATCH 1/7] add notify to end of subscribe call --- .../io/branch/rnbranch/RNBranchModule.java | 50 ++++++++++++++++++- src/index.js | 5 ++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/io/branch/rnbranch/RNBranchModule.java b/android/src/main/java/io/branch/rnbranch/RNBranchModule.java index 843782c38..e8fe860b0 100644 --- a/android/src/main/java/io/branch/rnbranch/RNBranchModule.java +++ b/android/src/main/java/io/branch/rnbranch/RNBranchModule.java @@ -107,8 +107,10 @@ public static void getAutoInstance(Context context) { } public static void reInitSession(Activity reactActivity) { + Log.i("BranchTest","reInitSession " + reactActivity); Branch branch = Branch.getInstance(); Intent intent = reactActivity.getIntent(); + Log.i("BranchTest","reInitSession intent " + intent); if (intent != null) { intent.putExtra("branch_force_new_session", true); notifyJSOfInitSessionStart(reactActivity, intent.getData()); @@ -119,11 +121,14 @@ public static void reInitSession(Activity reactActivity) { } public static void initSession(final Uri uri, Activity reactActivity, Branch.BranchUniversalReferralInitListener anInitListener) { + Log.i("BranchTest","initSession uri " + uri + " reactActivity " + reactActivity + " anInitListener" + anInitListener); initListener = anInitListener; initSession(uri, reactActivity); } public static void initSession(final Uri uri, Activity reactActivity) { + Log.i("BranchTest","initSession uri " + uri + " reactActivity " + reactActivity); + Branch branch = setupBranch(reactActivity.getApplicationContext()); mActivity = reactActivity; @@ -134,6 +139,8 @@ public static void initSession(final Uri uri, Activity reactActivity) { @Override public void onInitFinished(JSONObject referringParams, BranchError error) { + Log.i("BranchTest","onInitFinished referringParams " + referringParams); + // react native currently expects this to never be null if (referringParams == null) { referringParams = new JSONObject(); @@ -156,12 +163,17 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { LinkProperties linkProperties = LinkProperties.getReferredLinkProperties(); if (initListener != null) { + Log.i("BranchTest","calling onInitFinished " + branchUniversalObject + " " + linkProperties +" " +error); initListener.onInitFinished(branchUniversalObject, linkProperties, error); } generateLocalBroadcast(referringParams, uri, branchUniversalObject, linkProperties, error); + + // post back, don't broadcast } private Branch.BranchReferralInitListener init(Activity activity) { + Log.i("BranchTest","init " + activity); + mmActivity = activity; return this; } @@ -171,6 +183,9 @@ private void generateLocalBroadcast(JSONObject referringParams, BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) { + + Log.i("BranchTest","generateLocalBroadcast referringParams " + referringParams + " uri " + uri + " " + linkProperties + " error " + error); + Intent broadcastIntent = new Intent(NATIVE_INIT_SESSION_FINISHED_EVENT); if (referringParams != null) { @@ -197,6 +212,8 @@ private void generateLocalBroadcast(JSONObject referringParams, broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_ERROR, error.getMessage()); } + Log.i("BranchTest","sending broadcast " + broadcastIntent); + LocalBroadcastManager.getInstance(mmActivity).sendBroadcast(broadcastIntent); } }.init(reactActivity); @@ -215,6 +232,7 @@ private void generateLocalBroadcast(JSONObject referringParams, * @param intent the new Intent received via Activity.onNewIntent */ public static void onNewIntent(@Nonnull Intent intent) { + Log.i("BranchTest","onNewIntent " + intent); mActivity.setIntent(intent); mNewIntent = true; reInitSession(mActivity); @@ -227,6 +245,8 @@ public static void onNewIntent(@Nonnull Intent intent) { * @param uri the URI to include in the notification or null */ private static void notifyJSOfInitSessionStart(Context context, Uri uri) { + Log.i("BranchTest","notifyJSOfInitSessionStart " + uri); + /* * This check just ensures that we only generate one RNBranch.initSessionStart * event per call to onNewIntent(). @@ -239,6 +259,7 @@ private static void notifyJSOfInitSessionStart(Context context, Uri uri) { broadcastIntent.putExtra(NATIVE_INIT_SESSION_STARTED_EVENT_URI, uri); } + Log.i("BranchTest", "Broadcasting NATIVE_INIT_SESSION_STARTED_EVENT"); LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent); Log.d(REACT_CLASS, "Sent session start broadcast for " + uri); } @@ -248,6 +269,7 @@ private static void notifyJSOfInitSessionStart(Context context, Uri uri) { * logging, please invoke enableLogging. If you wish to simulate installs, please Test Devices * (https://help.branch.io/using-branch/docs/adding-test-devices) */ + @Deprecated public static void setDebug() { } public static void enableLogging() { @@ -322,22 +344,31 @@ public Map getConstants() { } private void listenForInitSessionEventsToReactNative(ReactApplicationContext reactContext) { + Log.i("BranchTest","listenForInitSessionEventsToReactNative " + reactContext); + mInitSessionFinishedEventReceiver = new BroadcastReceiver() { RNBranchModule mBranchModule; @Override public void onReceive(Context context, Intent intent) { + Log.i("BranchTest","onReceive " + intent); + final boolean hasError = (initSessionResult.has("error") && !initSessionResult.isNull("error")); final String eventName = hasError ? RN_INIT_SESSION_ERROR_EVENT : RN_INIT_SESSION_SUCCESS_EVENT; + Log.i("BranchTest","sendRNEvent " + eventName); mBranchModule.sendRNEvent(eventName, convertJsonToMap(initSessionResult)); } private BroadcastReceiver init(RNBranchModule branchModule) { + Log.i("BranchTest","init " + branchModule); + mBranchModule = branchModule; return this; } }.init(this); + Log.i("BranchTest","registering receiver"); + LocalBroadcastManager.getInstance(reactContext).registerReceiver(mInitSessionFinishedEventReceiver, new IntentFilter(NATIVE_INIT_SESSION_FINISHED_EVENT)); mInitSessionStartedEventReceiver = new BroadcastReceiver() { @@ -345,6 +376,8 @@ private BroadcastReceiver init(RNBranchModule branchModule) { @Override public void onReceive(Context context, Intent intent) { + Log.i("BranchTest","mInitSessionStartedEventReceiver " + context + " intent " + intent); + Uri uri = intent.getParcelableExtra(NATIVE_INIT_SESSION_STARTED_EVENT_URI); WritableMap payload = new WritableNativeMap(); if (uri != null) { @@ -357,6 +390,8 @@ public void onReceive(Context context, Intent intent) { } private BroadcastReceiver init(RNBranchModule branchModule) { + Log.i("BranchTest","init " + branchModule); + mBranchModule = branchModule; return this; } @@ -367,6 +402,8 @@ private BroadcastReceiver init(RNBranchModule branchModule) { @Override public void onCatalystInstanceDestroy() { + Log.i("BranchTest","onCatalystInstanceDestroy "); + LocalBroadcastManager.getInstance(getReactApplicationContext()).unregisterReceiver(mInitSessionFinishedEventReceiver); LocalBroadcastManager.getInstance(getReactApplicationContext()).unregisterReceiver(mInitSessionStartedEventReceiver); } @@ -376,6 +413,12 @@ public String getName() { return NAME; } + @ReactMethod + public void notifyNativeToInit(){ + Log.d(REACT_CLASS, "notifyNativeToInit"); + Branch.notifyNativeToInit(); + } + @ReactMethod public void disableTracking(boolean disable) { Branch branch = Branch.getInstance(); @@ -406,6 +449,8 @@ public void releaseUniversalObject(String ident) { @ReactMethod public void redeemInitSessionResult(Promise promise) { + Log.i("BranchTest","redeemInitSessionResult " + promise + " initsessionresult " + initSessionResult); + promise.resolve(convertJsonToMap(initSessionResult)); } @@ -831,7 +876,8 @@ public static LinkProperties createLinkProperties(ReadableMap linkPropertiesMap, } private static Branch setupBranch(Context context) { - Branch branch = Branch.getInstance(context); + Log.i("BranchTest", "setupBranch"); + Branch branch = Branch.getAutoInstance(context); if (!mInitialized) { Log.i(REACT_CLASS, "Initializing Branch SDK v. " + BuildConfig.VERSION_NAME); @@ -851,6 +897,8 @@ private static Branch setupBranch(Context context) { mInitialized = true; } + Log.i("BranchTest", "setupBranch is initialized " + mInitialized); + return branch; } diff --git a/src/index.js b/src/index.js index 925297914..3f69b65b3 100644 --- a/src/index.js +++ b/src/index.js @@ -44,6 +44,11 @@ class Branch { const subscriber = new BranchSubscriber(options) subscriber.subscribe() + Platform.select({ + android: () => RNBranch.notifyNativeToInit() + //ios: () => RNBranch.notifyNativeToInit() //TODO: implement iOS side + }) + return () => subscriber.unsubscribe() } From a4dd7697e0f53dc34cab7a0a76a3f45746c4a335 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Mon, 6 Mar 2023 16:57:13 -0800 Subject: [PATCH 2/7] Update RNBranchModule.java --- .../io/branch/rnbranch/RNBranchModule.java | 57 ++++++------------- 1 file changed, 17 insertions(+), 40 deletions(-) diff --git a/android/src/main/java/io/branch/rnbranch/RNBranchModule.java b/android/src/main/java/io/branch/rnbranch/RNBranchModule.java index e8fe860b0..aeae7969f 100644 --- a/android/src/main/java/io/branch/rnbranch/RNBranchModule.java +++ b/android/src/main/java/io/branch/rnbranch/RNBranchModule.java @@ -107,10 +107,9 @@ public static void getAutoInstance(Context context) { } public static void reInitSession(Activity reactActivity) { - Log.i("BranchTest","reInitSession " + reactActivity); Branch branch = Branch.getInstance(); Intent intent = reactActivity.getIntent(); - Log.i("BranchTest","reInitSession intent " + intent); + Log.d(REACT_CLASS,"reInitSession intent " + intent); if (intent != null) { intent.putExtra("branch_force_new_session", true); notifyJSOfInitSessionStart(reactActivity, intent.getData()); @@ -121,13 +120,13 @@ public static void reInitSession(Activity reactActivity) { } public static void initSession(final Uri uri, Activity reactActivity, Branch.BranchUniversalReferralInitListener anInitListener) { - Log.i("BranchTest","initSession uri " + uri + " reactActivity " + reactActivity + " anInitListener" + anInitListener); + Log.d(REACT_CLASS,"initSession uri " + uri + " reactActivity " + reactActivity + " anInitListener" + anInitListener); initListener = anInitListener; initSession(uri, reactActivity); } public static void initSession(final Uri uri, Activity reactActivity) { - Log.i("BranchTest","initSession uri " + uri + " reactActivity " + reactActivity); + Log.d(REACT_CLASS,"initSession uri " + uri + " reactActivity " + reactActivity); Branch branch = setupBranch(reactActivity.getApplicationContext()); @@ -139,7 +138,7 @@ public static void initSession(final Uri uri, Activity reactActivity) { @Override public void onInitFinished(JSONObject referringParams, BranchError error) { - Log.i("BranchTest","onInitFinished referringParams " + referringParams); + Log.d(REACT_CLASS,"onInitFinished referringParams " + referringParams); // react native currently expects this to never be null if (referringParams == null) { @@ -155,7 +154,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, isNewIntent && uri != null ? uri.toString() : JSONObject.NULL); } catch (JSONException e) { - + Log.e(REACT_CLASS, e.getMessage()); } initSessionResult = result; @@ -163,17 +162,13 @@ public void onInitFinished(JSONObject referringParams, BranchError error) { LinkProperties linkProperties = LinkProperties.getReferredLinkProperties(); if (initListener != null) { - Log.i("BranchTest","calling onInitFinished " + branchUniversalObject + " " + linkProperties +" " +error); + Log.d(REACT_CLASS,"onInitFinished " + branchUniversalObject + " " + linkProperties + " error " +error); initListener.onInitFinished(branchUniversalObject, linkProperties, error); } generateLocalBroadcast(referringParams, uri, branchUniversalObject, linkProperties, error); - - // post back, don't broadcast } private Branch.BranchReferralInitListener init(Activity activity) { - Log.i("BranchTest","init " + activity); - mmActivity = activity; return this; } @@ -183,9 +178,7 @@ private void generateLocalBroadcast(JSONObject referringParams, BranchUniversalObject branchUniversalObject, LinkProperties linkProperties, BranchError error) { - - Log.i("BranchTest","generateLocalBroadcast referringParams " + referringParams + " uri " + uri + " " + linkProperties + " error " + error); - + Intent broadcastIntent = new Intent(NATIVE_INIT_SESSION_FINISHED_EVENT); if (referringParams != null) { @@ -212,14 +205,15 @@ private void generateLocalBroadcast(JSONObject referringParams, broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_ERROR, error.getMessage()); } - Log.i("BranchTest","sending broadcast " + broadcastIntent); - LocalBroadcastManager.getInstance(mmActivity).sendBroadcast(broadcastIntent); } }.init(reactActivity); notifyJSOfInitSessionStart(reactActivity, uri); - Branch.sessionBuilder(reactActivity).withCallback(referralInitListener).withData(uri).init(); + + Branch.InitSessionBuilder initSessionBuilder = Branch.sessionBuilder(reactActivity).withCallback(referralInitListener).withData(uri); + Log.d(REACT_CLASS, "sessionBuilder " + initSessionBuilder); + initSessionBuilder.init(); } /** @@ -232,7 +226,7 @@ private void generateLocalBroadcast(JSONObject referringParams, * @param intent the new Intent received via Activity.onNewIntent */ public static void onNewIntent(@Nonnull Intent intent) { - Log.i("BranchTest","onNewIntent " + intent); + Log.d(REACT_CLASS,"onNewIntent " + intent); mActivity.setIntent(intent); mNewIntent = true; reInitSession(mActivity); @@ -245,7 +239,7 @@ public static void onNewIntent(@Nonnull Intent intent) { * @param uri the URI to include in the notification or null */ private static void notifyJSOfInitSessionStart(Context context, Uri uri) { - Log.i("BranchTest","notifyJSOfInitSessionStart " + uri); + Log.d(REACT_CLASS,"notifyJSOfInitSessionStart " + uri); /* * This check just ensures that we only generate one RNBranch.initSessionStart @@ -259,9 +253,8 @@ private static void notifyJSOfInitSessionStart(Context context, Uri uri) { broadcastIntent.putExtra(NATIVE_INIT_SESSION_STARTED_EVENT_URI, uri); } - Log.i("BranchTest", "Broadcasting NATIVE_INIT_SESSION_STARTED_EVENT"); + Log.d(REACT_CLASS, "Broadcasting NATIVE_INIT_SESSION_STARTED_EVENT"); LocalBroadcastManager.getInstance(context).sendBroadcast(broadcastIntent); - Log.d(REACT_CLASS, "Sent session start broadcast for " + uri); } /** @@ -344,31 +337,23 @@ public Map getConstants() { } private void listenForInitSessionEventsToReactNative(ReactApplicationContext reactContext) { - Log.i("BranchTest","listenForInitSessionEventsToReactNative " + reactContext); - mInitSessionFinishedEventReceiver = new BroadcastReceiver() { RNBranchModule mBranchModule; @Override public void onReceive(Context context, Intent intent) { - Log.i("BranchTest","onReceive " + intent); - final boolean hasError = (initSessionResult.has("error") && !initSessionResult.isNull("error")); final String eventName = hasError ? RN_INIT_SESSION_ERROR_EVENT : RN_INIT_SESSION_SUCCESS_EVENT; - Log.i("BranchTest","sendRNEvent " + eventName); + mBranchModule.sendRNEvent(eventName, convertJsonToMap(initSessionResult)); } private BroadcastReceiver init(RNBranchModule branchModule) { - Log.i("BranchTest","init " + branchModule); - mBranchModule = branchModule; return this; } }.init(this); - Log.i("BranchTest","registering receiver"); - LocalBroadcastManager.getInstance(reactContext).registerReceiver(mInitSessionFinishedEventReceiver, new IntentFilter(NATIVE_INIT_SESSION_FINISHED_EVENT)); mInitSessionStartedEventReceiver = new BroadcastReceiver() { @@ -376,8 +361,6 @@ private BroadcastReceiver init(RNBranchModule branchModule) { @Override public void onReceive(Context context, Intent intent) { - Log.i("BranchTest","mInitSessionStartedEventReceiver " + context + " intent " + intent); - Uri uri = intent.getParcelableExtra(NATIVE_INIT_SESSION_STARTED_EVENT_URI); WritableMap payload = new WritableNativeMap(); if (uri != null) { @@ -390,8 +373,6 @@ public void onReceive(Context context, Intent intent) { } private BroadcastReceiver init(RNBranchModule branchModule) { - Log.i("BranchTest","init " + branchModule); - mBranchModule = branchModule; return this; } @@ -402,7 +383,7 @@ private BroadcastReceiver init(RNBranchModule branchModule) { @Override public void onCatalystInstanceDestroy() { - Log.i("BranchTest","onCatalystInstanceDestroy "); + Log.d(REACT_CLASS,"onCatalystInstanceDestroy "); LocalBroadcastManager.getInstance(getReactApplicationContext()).unregisterReceiver(mInitSessionFinishedEventReceiver); LocalBroadcastManager.getInstance(getReactApplicationContext()).unregisterReceiver(mInitSessionStartedEventReceiver); @@ -449,8 +430,6 @@ public void releaseUniversalObject(String ident) { @ReactMethod public void redeemInitSessionResult(Promise promise) { - Log.i("BranchTest","redeemInitSessionResult " + promise + " initsessionresult " + initSessionResult); - promise.resolve(convertJsonToMap(initSessionResult)); } @@ -726,6 +705,7 @@ public void onLinkCreate(String url, BranchError error) { @ReactMethod public void openURL(String url, ReadableMap options) { + Log.d(REACT_CLASS, "openURL url: " + url); if (mActivity == null) { // initSession is called before JS loads. This probably indicates failure to call initSession // in an activity. @@ -876,7 +856,6 @@ public static LinkProperties createLinkProperties(ReadableMap linkPropertiesMap, } private static Branch setupBranch(Context context) { - Log.i("BranchTest", "setupBranch"); Branch branch = Branch.getAutoInstance(context); if (!mInitialized) { @@ -897,8 +876,6 @@ private static Branch setupBranch(Context context) { mInitialized = true; } - Log.i("BranchTest", "setupBranch is initialized " + mInitialized); - return branch; } From 7dd90a9d687d8e9303260b93aef939486d765c8c Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Mon, 6 Mar 2023 16:58:08 -0800 Subject: [PATCH 3/7] Update build.gradle --- android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index a00ad0b23..ae2ce8ccf 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -47,5 +47,5 @@ def safeExtGet(prop, fallback) { dependencies { implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' implementation 'com.facebook.react:react-native:+' // From node_modules - api 'io.branch.sdk.android:library:5.2.7' + api 'io.branch.sdk.android:library:5.3.0' } From 815fc88096227cf087c33948bc2420321d33bf53 Mon Sep 17 00:00:00 2001 From: Jagadeesh Karicherla Date: Thu, 16 Mar 2023 08:45:51 -0700 Subject: [PATCH 4/7] invoke IOS notifyNativeToInit --- ios/RNBranch.m | 7 +++++++ react-native-branch.podspec | 2 +- src/index.js | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ios/RNBranch.m b/ios/RNBranch.m index cf09f6c57..998121664 100644 --- a/ios/RNBranch.m +++ b/ios/RNBranch.m @@ -448,6 +448,13 @@ - (BranchUniversalObject *)findUniversalObjectWithIdent:(NSString *)ident reject [self.class.branch handleDeepLinkWithNewSession:[NSURL URLWithString:urlString]]; } +#pragma mark notifyNativeToInit +RCT_EXPORT_METHOD( + notifyNativeToInit + ) { + [self.class.branch notifyNativeToInit]; +} + #pragma mark sendCommerceEvent RCT_EXPORT_METHOD( sendCommerceEvent:(NSString *)revenue diff --git a/react-native-branch.podspec b/react-native-branch.podspec index b411610fe..a47e7a35d 100644 --- a/react-native-branch.podspec +++ b/react-native-branch.podspec @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.source_files = [ "ios/*.h", "ios/*.m"] s.compiler_flags = %[-DRNBRANCH_VERSION=@\\"#{s.version}\\"] s.header_dir = 'RNBranch' # also sets generated module name - s.dependency 'Branch', '1.45.2' + s.dependency 'Branch', '2.1.0' s.dependency 'React-Core' # to ensure the correct build order # Swift/Objective-C compatibility diff --git a/src/index.js b/src/index.js index 3f69b65b3..f581deaa5 100644 --- a/src/index.js +++ b/src/index.js @@ -45,8 +45,8 @@ class Branch { subscriber.subscribe() Platform.select({ - android: () => RNBranch.notifyNativeToInit() - //ios: () => RNBranch.notifyNativeToInit() //TODO: implement iOS side + android: () => RNBranch.notifyNativeToInit(), + ios: () => RNBranch.notifyNativeToInit() }) return () => subscriber.unsubscribe() From ea4244049f4a84526b543c4c594db02d85ee639c Mon Sep 17 00:00:00 2001 From: Jagadeesh Karicherla Date: Tue, 21 Mar 2023 16:19:50 -0700 Subject: [PATCH 5/7] update ios Branch to BranchSDK 2.1.0 --- ios/BranchContentMetadata+RNBranch.h | 2 +- ios/BranchEvent+RNBranch.h | 6 +++--- ios/BranchLinkProperties+RNBranch.h | 4 ++-- ios/BranchUniversalObject+RNBranch.h | 4 ++-- ios/RNBranch.h | 4 +++- ios/RNBranch.m | 1 + ios/RNBranchProperty.h | 2 +- native-tests/ios/NativeTestsTests/RNBranchTests.m | 2 +- react-native-branch.podspec | 2 +- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ios/BranchContentMetadata+RNBranch.h b/ios/BranchContentMetadata+RNBranch.h index 936792a09..2eb3ea36c 100644 --- a/ios/BranchContentMetadata+RNBranch.h +++ b/ios/BranchContentMetadata+RNBranch.h @@ -5,7 +5,7 @@ // Created by Jimmy Dee on 12/6/17. // -#import +#import @interface BranchContentMetadata(RNBranch) diff --git a/ios/BranchEvent+RNBranch.h b/ios/BranchEvent+RNBranch.h index 9aa4288cd..561e2e446 100644 --- a/ios/BranchEvent+RNBranch.h +++ b/ios/BranchEvent+RNBranch.h @@ -5,9 +5,9 @@ // Created by Jimmy Dee on 11/28/17. // -#import - -@interface BranchEvent(RNBranch) +#import +#import +@interface BranchEvent(RNBranch) - (instancetype)initWithName:(NSString *)eventName map:(NSDictionary *)map; diff --git a/ios/BranchLinkProperties+RNBranch.h b/ios/BranchLinkProperties+RNBranch.h index f2bec9af2..c8d804b6d 100644 --- a/ios/BranchLinkProperties+RNBranch.h +++ b/ios/BranchLinkProperties+RNBranch.h @@ -6,8 +6,8 @@ // Copyright © 2017 Branch Metrics. All rights reserved. // -#import - +#import +#import @class RNBranchProperty; @interface BranchLinkProperties(RNBranch) diff --git a/ios/BranchUniversalObject+RNBranch.h b/ios/BranchUniversalObject+RNBranch.h index 6ef339669..85ef21112 100644 --- a/ios/BranchUniversalObject+RNBranch.h +++ b/ios/BranchUniversalObject+RNBranch.h @@ -6,8 +6,8 @@ // Copyright © 2017 Branch Metrics. All rights reserved. // -#import - +#import +#import @class RNBranchProperty; @interface BranchUniversalObject(RNBranch) diff --git a/ios/RNBranch.h b/ios/RNBranch.h index e0eebe5c5..68c75a1b1 100644 --- a/ios/RNBranch.h +++ b/ios/RNBranch.h @@ -1,7 +1,9 @@ #import #import -#import +#import +#import +#import extern NSString * _Nonnull const RNBranchLinkOpenedNotification; extern NSString * _Nonnull const RNBranchLinkOpenedNotificationErrorKey; diff --git a/ios/RNBranch.m b/ios/RNBranch.m index 998121664..c7d8280e2 100644 --- a/ios/RNBranch.m +++ b/ios/RNBranch.m @@ -6,6 +6,7 @@ #import "BranchUniversalObject+RNBranch.h" #import "RNBranchAgingDictionary.h" #import "RNBranchEventEmitter.h" +#import NSString * const RNBranchLinkOpenedNotification = @"RNBranchLinkOpenedNotification"; NSString * const RNBranchLinkOpenedNotificationErrorKey = @"error"; diff --git a/ios/RNBranchProperty.h b/ios/RNBranchProperty.h index 2c1054483..da3e4d26f 100644 --- a/ios/RNBranchProperty.h +++ b/ios/RNBranchProperty.h @@ -6,7 +6,7 @@ // Copyright © 2017 Branch Metrics. All rights reserved. // -#import +#import /* * Utility class to represent dynamically all supported JS properties on BranchUniversalObject and BranchLinkProperties. diff --git a/native-tests/ios/NativeTestsTests/RNBranchTests.m b/native-tests/ios/NativeTestsTests/RNBranchTests.m index 4bf41c0af..fa14f9017 100644 --- a/native-tests/ios/NativeTestsTests/RNBranchTests.m +++ b/native-tests/ios/NativeTestsTests/RNBranchTests.m @@ -9,7 +9,7 @@ #import #import #import -#import +#import #define ASSERT_CONSTANT(constantName, expectedValue) \ NSString *constant = self.rnbranch.constantsToExport[constantName]; \ diff --git a/react-native-branch.podspec b/react-native-branch.podspec index a47e7a35d..134fae011 100644 --- a/react-native-branch.podspec +++ b/react-native-branch.podspec @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.source_files = [ "ios/*.h", "ios/*.m"] s.compiler_flags = %[-DRNBRANCH_VERSION=@\\"#{s.version}\\"] s.header_dir = 'RNBranch' # also sets generated module name - s.dependency 'Branch', '2.1.0' + s.dependency 'BranchSDK', '2.1.0' s.dependency 'React-Core' # to ensure the correct build order # Swift/Objective-C compatibility From 3324c493822c5ecd63677c8060fbf8cc3b89e2dc Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Wed, 29 Mar 2023 03:46:24 -0700 Subject: [PATCH 6/7] clean up, comments, implement in testbed --- ChangeLog.md | 17 +++ .../android/app/src/main/assets/branch.json | 4 + .../components/BranchWrapper.ts | 2 +- branchreactnativetestbed/ios/Podfile.lock | 12 +- branchreactnativetestbed/ios/branch.json | 4 + .../project.pbxproj | 134 +++++++++--------- .../branchreactnativetestbed/AppDelegate.mm | 1 - branchreactnativetestbed/package-lock.json | 14 +- branchreactnativetestbed/package.json | 2 +- package.json | 2 +- src/BranchSubscriber.js | 18 ++- src/index.js | 5 - 12 files changed, 127 insertions(+), 88 deletions(-) create mode 100644 branchreactnativetestbed/android/app/src/main/assets/branch.json create mode 100644 branchreactnativetestbed/ios/branch.json diff --git a/ChangeLog.md b/ChangeLog.md index 8a33d28d5..ae7ee3fc6 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,20 @@ +2023-03-29 + - To address a race condition where apps don't receive Branch params on cold starts, an opt in fix will defer loading the native iOS/Android layer until signalled + by this plugin in `subscribe()`. + This can be enabled by creating a `branch.json` file with the contents: + ```js + { + "deferInitForPluginRuntime": true + } + ``` + Android: Place this file in your src/main/assets folder + iOS: Add this file through Xcode, File -> Add Files to "YourProject.xcodeproj" + and add to Copy Bundle Resources for each target that inits the Branch SDK. + - Update Android SDK to 5.3.0 + - Update iOS SDK 2.1.0 + It may be necessary to clear out pod cache and reinstall + - Fixes the typing of `isTrackingDisabled` to return `Promise` + 2023-01-23 Version 5.7.0 - Update Android SDK to 5.2.7 - Update iOS SDK to 1.45.2 diff --git a/branchreactnativetestbed/android/app/src/main/assets/branch.json b/branchreactnativetestbed/android/app/src/main/assets/branch.json new file mode 100644 index 000000000..044b75fb2 --- /dev/null +++ b/branchreactnativetestbed/android/app/src/main/assets/branch.json @@ -0,0 +1,4 @@ +{ + "enableLogging": true, + "deferInitForPluginRuntime": true +} diff --git a/branchreactnativetestbed/components/BranchWrapper.ts b/branchreactnativetestbed/components/BranchWrapper.ts index c2d1c8ee5..be19d8456 100644 --- a/branchreactnativetestbed/components/BranchWrapper.ts +++ b/branchreactnativetestbed/components/BranchWrapper.ts @@ -1,4 +1,4 @@ -import {Alert, Modal} from 'react-native'; +import {Alert} from 'react-native'; import branch, {BranchEvent} from 'react-native-branch'; export default class BranchWrapper { diff --git a/branchreactnativetestbed/ios/Podfile.lock b/branchreactnativetestbed/ios/Podfile.lock index 9c4a397dd..bc7a96a19 100644 --- a/branchreactnativetestbed/ios/Podfile.lock +++ b/branchreactnativetestbed/ios/Podfile.lock @@ -1,6 +1,6 @@ PODS: - boost (1.76.0) - - Branch (1.45.2) + - BranchSDK (2.1.0) - CocoaAsyncSocket (7.6.5) - DoubleConversion (1.1.6) - FBLazyVector (0.71.4) @@ -330,8 +330,8 @@ PODS: - React-jsinspector (0.71.4) - React-logger (0.71.4): - glog - - react-native-branch (5.7.0): - - Branch (= 1.45.2) + - react-native-branch (5.8.0-alpha.2): + - BranchSDK (= 2.1.0) - React-Core - React-perflogger (0.71.4) - React-RCTActionSheet (0.71.4): @@ -486,7 +486,7 @@ DEPENDENCIES: SPEC REPOS: trunk: - - Branch + - BranchSDK - CocoaAsyncSocket - Flipper - Flipper-Boost-iOSX @@ -577,7 +577,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: boost: 57d2868c099736d80fcd648bf211b4431e51a558 - Branch: 1fc81857f63403d4682305088b11270719dca8db + BranchSDK: ce28650272c658fcdb66675769e670ef83845d17 CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99 DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 FBLazyVector: 446e84642979fff0ba57f3c804c2228a473aeac2 @@ -610,7 +610,7 @@ SPEC CHECKSUMS: React-jsiexecutor: d6b7fa9260aa3cb40afee0507e3bc1d17ecaa6f2 React-jsinspector: 1f51e775819199d3fe9410e69ee8d4c4161c7b06 React-logger: 0d58569ec51d30d1792c5e86a8e3b78d24b582c6 - react-native-branch: 882341157fe7f47b0d8ac05b722040075eeefb7e + react-native-branch: a1d770fbde5cc8706f9507771ad98917e1380d17 React-perflogger: 0bb0522a12e058f6eb69d888bc16f40c16c4b907 React-RCTActionSheet: bfd675a10f06a18728ea15d82082d48f228a213a React-RCTAnimation: 2fa220b2052ec75b733112aca39143d34546a941 diff --git a/branchreactnativetestbed/ios/branch.json b/branchreactnativetestbed/ios/branch.json new file mode 100644 index 000000000..044b75fb2 --- /dev/null +++ b/branchreactnativetestbed/ios/branch.json @@ -0,0 +1,4 @@ +{ + "enableLogging": true, + "deferInitForPluginRuntime": true +} diff --git a/branchreactnativetestbed/ios/branchreactnativetestbed.xcodeproj/project.pbxproj b/branchreactnativetestbed/ios/branchreactnativetestbed.xcodeproj/project.pbxproj index 7c221ed7f..c72d35416 100644 --- a/branchreactnativetestbed/ios/branchreactnativetestbed.xcodeproj/project.pbxproj +++ b/branchreactnativetestbed/ios/branchreactnativetestbed.xcodeproj/project.pbxproj @@ -8,12 +8,13 @@ /* Begin PBXBuildFile section */ 00E356F31AD99517003FC87E /* branchreactnativetestbedTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* branchreactnativetestbedTests.m */; }; - 0C80B921A6F3F58F76C31292 /* libPods-branchreactnativetestbed.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-branchreactnativetestbed.a */; }; 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; }; 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; - 7699B88040F8A987B510C191 /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a */; }; + 35F0F027C316F91C23CB7CE9 /* libPods-branchreactnativetestbed.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CF49690E2DE41ADBA0D501EE /* libPods-branchreactnativetestbed.a */; }; + 4DB3623629D43C3700D29789 /* branch.json in Resources */ = {isa = PBXBuildFile; fileRef = 4DB3623529D43C3600D29789 /* branch.json */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; + EE27CDFF4536405DD3E861BE /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FF1CF6698C96757BCB73723A /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -30,21 +31,22 @@ 00E356EE1AD99517003FC87E /* branchreactnativetestbedTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = branchreactnativetestbedTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 00E356F21AD99517003FC87E /* branchreactnativetestbedTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = branchreactnativetestbedTests.m; sourceTree = ""; }; + 0DBF9ADFCD1FE3776CC6A9E1 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig"; sourceTree = ""; }; + 0FAE99625EA3F5885ED6A092 /* Pods-branchreactnativetestbed.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed.debug.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed.debug.xcconfig"; sourceTree = ""; }; 13B07F961A680F5B00A75B9A /* branchreactnativetestbed.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = branchreactnativetestbed.app; sourceTree = BUILT_PRODUCTS_DIR; }; 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = branchreactnativetestbed/AppDelegate.h; sourceTree = ""; }; 13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = branchreactnativetestbed/AppDelegate.mm; sourceTree = ""; }; 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = branchreactnativetestbed/Images.xcassets; sourceTree = ""; }; 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = branchreactnativetestbed/Info.plist; sourceTree = ""; }; 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = branchreactnativetestbed/main.m; sourceTree = ""; }; - 19F6CBCC0A4E27FBF8BF4A61 /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-branchreactnativetestbed-branchreactnativetestbedTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 3B4392A12AC88292D35C810B /* Pods-branchreactnativetestbed.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed.debug.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed.debug.xcconfig"; sourceTree = ""; }; 4DAFD81029C1B14100EA4789 /* branchreactnativetestbed.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = branchreactnativetestbed.entitlements; path = branchreactnativetestbed/branchreactnativetestbed.entitlements; sourceTree = ""; }; - 5709B34CF0A7D63546082F79 /* Pods-branchreactnativetestbed.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed.release.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed.release.xcconfig"; sourceTree = ""; }; - 5B7EB9410499542E8C5724F5 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig"; sourceTree = ""; }; - 5DCACB8F33CDC322A6C60F78 /* libPods-branchreactnativetestbed.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-branchreactnativetestbed.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 4DB3623529D43C3600D29789 /* branch.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = branch.json; sourceTree = ""; }; 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = branchreactnativetestbed/LaunchScreen.storyboard; sourceTree = ""; }; - 89C6BE57DB24E9ADA2F236DE /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig"; sourceTree = ""; }; + 97234E4EFD341F2BEB1055B8 /* Pods-branchreactnativetestbed.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed.release.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed.release.xcconfig"; sourceTree = ""; }; + CF49690E2DE41ADBA0D501EE /* libPods-branchreactnativetestbed.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-branchreactnativetestbed.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + D85B1EE45650E2D123BEFD82 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig"; path = "Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; + FF1CF6698C96757BCB73723A /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-branchreactnativetestbed-branchreactnativetestbedTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -52,7 +54,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 7699B88040F8A987B510C191 /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a in Frameworks */, + EE27CDFF4536405DD3E861BE /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -60,7 +62,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0C80B921A6F3F58F76C31292 /* libPods-branchreactnativetestbed.a in Frameworks */, + 35F0F027C316F91C23CB7CE9 /* libPods-branchreactnativetestbed.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -90,6 +92,7 @@ 4DAFD81029C1B14100EA4789 /* branchreactnativetestbed.entitlements */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 13B07FB01A68108700A75B9A /* AppDelegate.mm */, + 4DB3623529D43C3600D29789 /* branch.json */, 13B07FB51A68108700A75B9A /* Images.xcassets */, 13B07FB61A68108700A75B9A /* Info.plist */, 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, @@ -102,8 +105,8 @@ isa = PBXGroup; children = ( ED297162215061F000B7C4FE /* JavaScriptCore.framework */, - 5DCACB8F33CDC322A6C60F78 /* libPods-branchreactnativetestbed.a */, - 19F6CBCC0A4E27FBF8BF4A61 /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a */, + CF49690E2DE41ADBA0D501EE /* libPods-branchreactnativetestbed.a */, + FF1CF6698C96757BCB73723A /* libPods-branchreactnativetestbed-branchreactnativetestbedTests.a */, ); name = Frameworks; sourceTree = ""; @@ -142,10 +145,10 @@ BBD78D7AC51CEA395F1C20DB /* Pods */ = { isa = PBXGroup; children = ( - 3B4392A12AC88292D35C810B /* Pods-branchreactnativetestbed.debug.xcconfig */, - 5709B34CF0A7D63546082F79 /* Pods-branchreactnativetestbed.release.xcconfig */, - 5B7EB9410499542E8C5724F5 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig */, - 89C6BE57DB24E9ADA2F236DE /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig */, + 0FAE99625EA3F5885ED6A092 /* Pods-branchreactnativetestbed.debug.xcconfig */, + 97234E4EFD341F2BEB1055B8 /* Pods-branchreactnativetestbed.release.xcconfig */, + D85B1EE45650E2D123BEFD82 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig */, + 0DBF9ADFCD1FE3776CC6A9E1 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig */, ); path = Pods; sourceTree = ""; @@ -157,12 +160,12 @@ isa = PBXNativeTarget; buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "branchreactnativetestbedTests" */; buildPhases = ( - A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */, + 9E593705976EF340B618307F /* [CP] Check Pods Manifest.lock */, 00E356EA1AD99517003FC87E /* Sources */, 00E356EB1AD99517003FC87E /* Frameworks */, 00E356EC1AD99517003FC87E /* Resources */, - C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */, - F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */, + 282289BB3444D6E3323C0864 /* [CP] Embed Pods Frameworks */, + 3DDE5B17EA12E54B3861A4DA /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -178,14 +181,14 @@ isa = PBXNativeTarget; buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "branchreactnativetestbed" */; buildPhases = ( - C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */, + 5833E89BA37DC5C0052057CF /* [CP] Check Pods Manifest.lock */, FD10A7F022414F080027D42C /* Start Packager */, 13B07F871A680F5B00A75B9A /* Sources */, 13B07F8C1A680F5B00A75B9A /* Frameworks */, 13B07F8E1A680F5B00A75B9A /* Resources */, 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, - 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */, - E235C05ADACE081382539298 /* [CP] Copy Pods Resources */, + B49DBB0F84E2B2C11CE5D5BB /* [CP] Embed Pods Frameworks */, + 419DE778A239D8FB2D2A11AB /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -246,6 +249,7 @@ files = ( 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, + 4DB3623629D43C3700D29789 /* branch.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -268,116 +272,116 @@ shellPath = /bin/sh; shellScript = "set -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n"; }; - 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = { + 282289BB3444D6E3323C0864 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-frameworks-${CONFIGURATION}-input-files.xcfilelist", + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-frameworks-${CONFIGURATION}-output-files.xcfilelist", + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-frameworks.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = { + 3DDE5B17EA12E54B3861A4DA /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Copy Pods Resources"; outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-branchreactnativetestbed-branchreactnativetestbedTests-checkManifestLockResult.txt", + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-resources-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; - C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = { + 419DE778A239D8FB2D2A11AB /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-resources-${CONFIGURATION}-input-files.xcfilelist", ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Copy Pods Resources"; outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-branchreactnativetestbed-checkManifestLockResult.txt", + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-resources-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-resources.sh\"\n"; showEnvVarsInLog = 0; }; - C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */ = { + 5833E89BA37DC5C0052057CF /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - name = "[CP] Embed Pods Frameworks"; + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-branchreactnativetestbed-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = { + 9E593705976EF340B618307F /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-resources-${CONFIGURATION}-input-files.xcfilelist", ); - name = "[CP] Copy Pods Resources"; + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-branchreactnativetestbed-branchreactnativetestbedTests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */ = { + B49DBB0F84E2B2C11CE5D5BB /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-resources-${CONFIGURATION}-input-files.xcfilelist", + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - name = "[CP] Copy Pods Resources"; + name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-resources-${CONFIGURATION}-output-files.xcfilelist", + "${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed-branchreactnativetestbedTests/Pods-branchreactnativetestbed-branchreactnativetestbedTests-resources.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-branchreactnativetestbed/Pods-branchreactnativetestbed-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; FD10A7F022414F080027D42C /* Start Packager */ = { @@ -432,7 +436,7 @@ /* Begin XCBuildConfiguration section */ 00E356F61AD99517003FC87E /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig */; + baseConfigurationReference = D85B1EE45650E2D123BEFD82 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -459,7 +463,7 @@ }; 00E356F71AD99517003FC87E /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 89C6BE57DB24E9ADA2F236DE /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig */; + baseConfigurationReference = 0DBF9ADFCD1FE3776CC6A9E1 /* Pods-branchreactnativetestbed-branchreactnativetestbedTests.release.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; @@ -483,7 +487,7 @@ }; 13B07F941A680F5B00A75B9A /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-branchreactnativetestbed.debug.xcconfig */; + baseConfigurationReference = 0FAE99625EA3F5885ED6A092 /* Pods-branchreactnativetestbed.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; @@ -512,7 +516,7 @@ }; 13B07F951A680F5B00A75B9A /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-branchreactnativetestbed.release.xcconfig */; + baseConfigurationReference = 97234E4EFD341F2BEB1055B8 /* Pods-branchreactnativetestbed.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; diff --git a/branchreactnativetestbed/ios/branchreactnativetestbed/AppDelegate.mm b/branchreactnativetestbed/ios/branchreactnativetestbed/AppDelegate.mm index 530898e07..d4adcbe6c 100644 --- a/branchreactnativetestbed/ios/branchreactnativetestbed/AppDelegate.mm +++ b/branchreactnativetestbed/ios/branchreactnativetestbed/AppDelegate.mm @@ -12,7 +12,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( // They will be passed down to the ViewController used by React Native. self.initialProps = @{}; - [RNBranch enableLogging]; [RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; diff --git a/branchreactnativetestbed/package-lock.json b/branchreactnativetestbed/package-lock.json index fa3ee3338..018f946c0 100644 --- a/branchreactnativetestbed/package-lock.json +++ b/branchreactnativetestbed/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "react": "18.2.0", "react-native": "0.71.4", - "react-native-branch": "^5.7.0" + "react-native-branch": "^5.8.0-alpha.2" }, "devDependencies": { "@babel/core": "^7.20.0", @@ -12894,9 +12894,9 @@ } }, "node_modules/react-native-branch": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/react-native-branch/-/react-native-branch-5.7.0.tgz", - "integrity": "sha512-f1NsH3HibkAl8Ar3fybNAd/2j6pS5V57x3DexJ6T5utsiU1ezaZyp6hXBAv9yhdCVYBxtXZqiK9mWQVnU6tKiw==", + "version": "5.8.0-alpha.2", + "resolved": "https://registry.npmjs.org/react-native-branch/-/react-native-branch-5.8.0-alpha.2.tgz", + "integrity": "sha512-S4JfXDd4EBsI+j/Rccx54SZu7TD5wcoohRryZalzeYi0GROo8JUXNXHvJyTkwJrg8yFT6AtpAvv/y0jUNhVdVw==", "peerDependencies": { "react-native": ">= 0.60" } @@ -24457,9 +24457,9 @@ } }, "react-native-branch": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/react-native-branch/-/react-native-branch-5.7.0.tgz", - "integrity": "sha512-f1NsH3HibkAl8Ar3fybNAd/2j6pS5V57x3DexJ6T5utsiU1ezaZyp6hXBAv9yhdCVYBxtXZqiK9mWQVnU6tKiw==", + "version": "5.8.0-alpha.2", + "resolved": "https://registry.npmjs.org/react-native-branch/-/react-native-branch-5.8.0-alpha.2.tgz", + "integrity": "sha512-S4JfXDd4EBsI+j/Rccx54SZu7TD5wcoohRryZalzeYi0GROo8JUXNXHvJyTkwJrg8yFT6AtpAvv/y0jUNhVdVw==", "requires": {} }, "react-native-codegen": { diff --git a/branchreactnativetestbed/package.json b/branchreactnativetestbed/package.json index f2d0af205..a4fdb07d1 100644 --- a/branchreactnativetestbed/package.json +++ b/branchreactnativetestbed/package.json @@ -12,7 +12,7 @@ "dependencies": { "react": "18.2.0", "react-native": "0.71.4", - "react-native-branch": "^5.7.0" + "react-native-branch": "^5.8.0-alpha.2" }, "devDependencies": { "@babel/core": "^7.20.0", diff --git a/package.json b/package.json index 8fc54d154..97ad59ed7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-branch", - "version": "5.7.0", + "version": "5.8.0", "description": "Branch Metrics React Native SDK", "main": "src/index.js", "types": "src/index.d.ts", diff --git a/src/BranchSubscriber.js b/src/BranchSubscriber.js index 0530d4c5d..d96cd1d35 100644 --- a/src/BranchSubscriber.js +++ b/src/BranchSubscriber.js @@ -67,7 +67,7 @@ export default class BranchSubscriber { } /* - * TODO: There can easily be a race here on cold launch from a link. + * There can easily be a race here on cold launch from a link. * An INIT_SESSION_START event can be emitted by the native layer * before the subscribe() method is called in JS. Then subscribe() is * called before a cached response is available, so here we get @@ -75,6 +75,16 @@ export default class BranchSubscriber { * transmitted to JS, and onOpenComplete is called with a non-null * URI, but onOpenStart was never called. This can be addressed * by caching the pending URI in the native layers. + * + * An opt in fix will defer loading the native iOS/Android layer until signalled + * by this plugin below. + * This can be enabled by creating a branch.json file with the contents: + { + "deferInitForPluginRuntime": true + } + * Android: Place this file in your src/main/assets folder + * iOS: Add this file through Xcode, File -> Add Files to "YourProject.xcodeproj" + * and add to Copy Bundle Resources for each target that inits the Branch SDK. */ if (this.options.onOpenStart && 'uri' in result) { this.options.onOpenStart({uri: result.uri, cachedInitialEvent: true}) @@ -91,6 +101,12 @@ export default class BranchSubscriber { else { this._subscribe() } + + // The plugin will make the call to the native layer to check if the init needs to be released + Platform.select({ + android: () => RNBranch.notifyNativeToInit(), + ios: () => RNBranch.notifyNativeToInit() + })() } /** diff --git a/src/index.js b/src/index.js index 46ed63753..0d181f6a4 100644 --- a/src/index.js +++ b/src/index.js @@ -44,11 +44,6 @@ class Branch { const subscriber = new BranchSubscriber(options) subscriber.subscribe() - Platform.select({ - android: () => RNBranch.notifyNativeToInit(), - ios: () => RNBranch.notifyNativeToInit() - }) - return () => subscriber.unsubscribe() } From efcba745e78cb956da8ff1bf46b7551eef3a5510 Mon Sep 17 00:00:00 2001 From: gdeluna-branch Date: Wed, 29 Mar 2023 04:11:20 -0700 Subject: [PATCH 7/7] typo --- ChangeLog.md | 2 +- src/BranchSubscriber.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index ae7ee3fc6..bf0905cd4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,5 @@ 2023-03-29 - - To address a race condition where apps don't receive Branch params on cold starts, an opt in fix will defer loading the native iOS/Android layer until signalled + - To address a race condition where apps don't receive Branch params on cold starts, an opt in fix will defer loading the native iOS/Android layer until signaled by this plugin in `subscribe()`. This can be enabled by creating a `branch.json` file with the contents: ```js diff --git a/src/BranchSubscriber.js b/src/BranchSubscriber.js index d96cd1d35..a857d99e5 100644 --- a/src/BranchSubscriber.js +++ b/src/BranchSubscriber.js @@ -76,7 +76,7 @@ export default class BranchSubscriber { * URI, but onOpenStart was never called. This can be addressed * by caching the pending URI in the native layers. * - * An opt in fix will defer loading the native iOS/Android layer until signalled + * An opt in fix will defer loading the native iOS/Android layer until signaled * by this plugin below. * This can be enabled by creating a branch.json file with the contents: {