From 40357e9a3148f4ae2b211b17ee8730375d88f85e Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:51:36 -0700 Subject: [PATCH 1/2] Added API initSessionWithSceneOptions -> Added new API BranchScene:initSessionWithSceneOptions -> Deprecated BranchScene: initSessionWithLaunchOptions -> Added wrapper init APIs in Branch class for including scene identifier. --- Sources/BranchSDK/Branch.m | 11 +++++++-- Sources/BranchSDK/BranchScene.m | 32 ++++++++++++++++++++++++++ Sources/BranchSDK/Public/Branch.h | 3 +++ Sources/BranchSDK/Public/BranchScene.h | 4 +++- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 9b4d4f87e..fa8e8fbfd 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -616,6 +616,12 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL) - (void)initSceneSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController registerDeepLinkHandler:(void (^)(BNCInitSessionResponse * _Nullable initResponse, NSError * _Nullable error))callback { + [self initSceneSessionWithLaunchOptions:options sceneIdentifier:nil isReferrable:isReferrable explicitlyRequestedReferrable:explicitlyRequestedReferrable automaticallyDisplayController:automaticallyDisplayController + registerDeepLinkHandler:callback]; +} + +- (void)initSceneSessionWithLaunchOptions:(NSDictionary *)options sceneIdentifier:(NSString *)sceneIdentifier isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController + registerDeepLinkHandler:(void (^)(BNCInitSessionResponse * _Nullable initResponse, NSError * _Nullable error))callback { NSMutableDictionary * optionsWithDeferredInit = [[NSMutableDictionary alloc ] initWithDictionary:options]; if (self.deferInitForPluginRuntime) { [optionsWithDeferredInit setObject:@1 forKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"]; @@ -624,11 +630,12 @@ - (void)initSceneSessionWithLaunchOptions:(NSDictionary *)options isReferrable:( } [self deferInitBlock:^{ self.sceneSessionInitWithCallback = callback; - [self initSessionWithLaunchOptions:(NSDictionary *)optionsWithDeferredInit isReferrable:isReferrable explicitlyRequestedReferrable:explicitlyRequestedReferrable automaticallyDisplayController:automaticallyDisplayController]; + [self initSessionWithLaunchOptions:(NSDictionary *)optionsWithDeferredInit sceneIdentifier:sceneIdentifier isReferrable:isReferrable explicitlyRequestedReferrable:explicitlyRequestedReferrable automaticallyDisplayController:automaticallyDisplayController]; }]; } - (void)initSessionWithLaunchOptions:(NSDictionary *)options + sceneIdentifier:(NSString *)sceneIdentifier isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController { @@ -650,7 +657,7 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options #endif if(pushURL || [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) ) { - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL reset:NO]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:pushURL reset:NO]; } } diff --git a/Sources/BranchSDK/BranchScene.m b/Sources/BranchSDK/BranchScene.m index cb176994e..f94cca6d5 100644 --- a/Sources/BranchSDK/BranchScene.m +++ b/Sources/BranchSDK/BranchScene.m @@ -35,6 +35,38 @@ - (void)initSessionWithLaunchOptions:(nullable NSDictionary *)options registerDe }]; } +- (void)initSessionWithSceneOptions:(nullable UISceneConnectionOptions *)connectionOptions scene:(UIScene *)scene + registerDeepLinkHandler:(void (^ _Nonnull)(NSDictionary * _Nullable params, NSError * _Nullable error, UIScene * _Nullable scene))callback { + + [[BranchLogger shared] logVerbose:[[NSString alloc] initWithFormat:@"connectionOptions : %@", connectionOptions.debugDescription ] error:nil]; + + NSMutableDictionary *launchOptions = [[NSMutableDictionary alloc] init]; + + if (connectionOptions.userActivities.count ) { + launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey] = connectionOptions.userActivities.allObjects ; + } + + if (connectionOptions.URLContexts.count ) { + launchOptions[UIApplicationLaunchOptionsURLKey] = connectionOptions.URLContexts.allObjects ; + } + + [[Branch getInstance] initSceneSessionWithLaunchOptions:launchOptions sceneIdentifier:scene.session.persistentIdentifier isReferrable:YES explicitlyRequestedReferrable:NO automaticallyDisplayController:NO registerDeepLinkHandler:^(BNCInitSessionResponse * _Nullable initResponse, NSError * _Nullable error) { + if (callback) { + if (initResponse) { + callback(initResponse.params, error, [self sceneForIdentifier:initResponse.sceneIdentifier]); + } else { + callback([NSDictionary new], error, [self sceneForIdentifier:initResponse.sceneIdentifier]); + } + } + }]; + + if (connectionOptions.userActivities.count) { + [self scene:scene continueUserActivity:connectionOptions.userActivities.allObjects.firstObject]; + } else if (connectionOptions.URLContexts.count) { + [self scene:scene openURLContexts:connectionOptions.URLContexts]; + } +} + - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity NS_EXTENSION_UNAVAILABLE("BranchScene does not support Extensions") { [[BranchLogger shared] logVerbose:@"BranchScene continueUserActivity" error:nil]; diff --git a/Sources/BranchSDK/Public/Branch.h b/Sources/BranchSDK/Public/Branch.h index 78b3f0387..54d37839a 100644 --- a/Sources/BranchSDK/Public/Branch.h +++ b/Sources/BranchSDK/Public/Branch.h @@ -437,6 +437,9 @@ extern NSString * __nonnull const BNCSpotlightFeature; - (void)initSceneSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController registerDeepLinkHandler:(void (^)(BNCInitSessionResponse * _Nullable initResponse, NSError * _Nullable error))callback; + +- (void)initSceneSessionWithLaunchOptions:(NSDictionary *)options sceneIdentifier:(NSString *)sceneIdentifier isReferrable:(BOOL)isReferrable explicitlyRequestedReferrable:(BOOL)explicitlyRequestedReferrable automaticallyDisplayController:(BOOL)automaticallyDisplayController + registerDeepLinkHandler:(void (^)(BNCInitSessionResponse * _Nullable initResponse, NSError * _Nullable error))callback; /** Allow Branch to handle a link opening the app, returning whether it was from a Branch link or not. diff --git a/Sources/BranchSDK/Public/BranchScene.h b/Sources/BranchSDK/Public/BranchScene.h index f0397d9fc..190bb3064 100644 --- a/Sources/BranchSDK/Public/BranchScene.h +++ b/Sources/BranchSDK/Public/BranchScene.h @@ -20,8 +20,10 @@ API_AVAILABLE(ios(13.0), macCatalyst(13.1)) + (BranchScene *)shared; - (void)initSessionWithLaunchOptions:(nullable NSDictionary *)options + registerDeepLinkHandler:(void (^ _Nonnull)(NSDictionary * _Nullable params, NSError * _Nullable error, UIScene * _Nullable scene))callback __attribute__((deprecated(("Use `initSessionWithSceneOptions:scene:registerDeepLinkHandler:` instead.")))); +- (void)initSessionWithSceneOptions:(nullable UISceneConnectionOptions *)options + scene:(UIScene *)scene registerDeepLinkHandler:(void (^ _Nonnull)(NSDictionary * _Nullable params, NSError * _Nullable error, UIScene * _Nullable scene))callback; - - (void)scene:(UIScene *)scene continueUserActivity:(NSUserActivity *)userActivity; - (void)scene:(UIScene *)scene openURLContexts:(NSSet *)URLContexts; From 34998fd49d4ae6ed865dcd80f585416c99c842ad Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:10:05 -0800 Subject: [PATCH 2/2] Removed extra log. --- Sources/BranchSDK/BranchScene.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/BranchSDK/BranchScene.m b/Sources/BranchSDK/BranchScene.m index f94cca6d5..06c759548 100644 --- a/Sources/BranchSDK/BranchScene.m +++ b/Sources/BranchSDK/BranchScene.m @@ -38,8 +38,6 @@ - (void)initSessionWithLaunchOptions:(nullable NSDictionary *)options registerDe - (void)initSessionWithSceneOptions:(nullable UISceneConnectionOptions *)connectionOptions scene:(UIScene *)scene registerDeepLinkHandler:(void (^ _Nonnull)(NSDictionary * _Nullable params, NSError * _Nullable error, UIScene * _Nullable scene))callback { - [[BranchLogger shared] logVerbose:[[NSString alloc] initWithFormat:@"connectionOptions : %@", connectionOptions.debugDescription ] error:nil]; - NSMutableDictionary *launchOptions = [[NSMutableDictionary alloc] init]; if (connectionOptions.userActivities.count ) {