-
Notifications
You must be signed in to change notification settings - Fork 230
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
SDK-2309 cache link data when initialization is deferred #1369
Changes from all commits
6b1270b
7b2b5db
d119dcb
b30349c
2009c84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,6 +157,7 @@ | |
// This is enabled by setting deferInitForPluginRuntime to true in branch.json | ||
@property (nonatomic, assign, readwrite) BOOL deferInitForPluginRuntime; | ||
@property (nonatomic, copy, nullable) void (^cachedInitBlock)(void); | ||
@property (nonatomic, copy, readwrite) NSString *cachedURLString; | ||
|
||
@end | ||
|
||
|
@@ -624,27 +625,20 @@ | |
[self.class addBranchSDKVersionToCrashlyticsReport]; | ||
self.shouldAutomaticallyDeepLink = automaticallyDisplayController; | ||
|
||
// If the SDK is already initialized, this means that initSession was called after other lifecycle calls. | ||
if (self.initializationStatus == BNCInitStatusInitialized) { | ||
[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil]; | ||
return; | ||
} | ||
|
||
// Save data from push notification on app launch | ||
// Check for Branch link in a push payload | ||
NSString *pushURL = nil; | ||
#if !TARGET_OS_TV | ||
if ([options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { | ||
id branchUrlFromPush = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey][BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY]; | ||
if ([branchUrlFromPush isKindOfClass:[NSString class]]) { | ||
self.preferenceHelper.universalLinkUrl = branchUrlFromPush; | ||
self.preferenceHelper.referringURL = branchUrlFromPush; | ||
pushURL = (NSString *)branchUrlFromPush; | ||
} | ||
} | ||
#endif | ||
|
||
// Handle case where there's no URI scheme or Universal Link. | ||
if (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) { | ||
[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil]; | ||
} | ||
[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment if there are any assumptions about from which lifecycle call(s) this must go through? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously we assumed that initSession always came first, and other lifecycle calls would follow. With the delay feature, we cannot assume that anymore and cache away links arriving from other lifecycle calls. So now there are no assumptions about where the initSession is coming from. |
||
} | ||
|
||
- (void)setDeepLinkDebugMode:(NSDictionary *)debugParams { | ||
|
@@ -1938,11 +1932,21 @@ | |
|
||
- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString { | ||
|
||
// ignore lifecycle calls while waiting for a plugin runtime. | ||
@synchronized (self) { | ||
if (self.deferInitForPluginRuntime) { | ||
[[BranchLogger shared] logDebug:@"Branch init is deferred, ignoring init call." error:nil]; | ||
if (urlString) { | ||
echo-branch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[[BranchLogger shared] logDebug:@"Branch init is deferred, caching link" error:nil]; | ||
self.cachedURLString = urlString; | ||
} else { | ||
[[BranchLogger shared] logDebug:@"Branch init is deferred, ignoring lifecycle call without a link" error:nil]; | ||
} | ||
return; | ||
} else { | ||
if (!urlString && self.cachedURLString) { | ||
urlString = self.cachedURLString; | ||
[[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Using cached link: %@", urlString] error:nil]; | ||
} | ||
self.cachedURLString = nil; | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code assumed that there would be a follow up link lifecycle call, but with delayed init that call may have already happened and the associated link saved off.
Currently researching if this change has side effects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some testing this appears to be a legacy check that hasn't been required in a long time. It did negatively impact apps are are using just an
AppDelegate
on cold launch with a delayed init. Removing the check fixes the issue.