Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[In Progress] Added API BranchScene:initSessionWithSceneOptions #1443

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand All @@ -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 {
Expand All @@ -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];
}
}

Expand Down
30 changes: 30 additions & 0 deletions Sources/BranchSDK/BranchScene.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ - (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 {

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];

Expand Down
3 changes: 3 additions & 0 deletions Sources/BranchSDK/Public/Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion Sources/BranchSDK/Public/BranchScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIOpenURLContext *> *)URLContexts;
Expand Down
Loading