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

Universal ink cold launch fix #1421

Merged
merged 6 commits into from
Aug 2, 2024
Merged

Conversation

NidhiDixit09
Copy link
Collaborator

@NidhiDixit09 NidhiDixit09 commented Aug 2, 2024

Fix for Universal Link Cold Launch

Summary

Issues -

-- If tracking is disabled and app launch is cold, Universal Links were not resolving intermittently because of race condition happening between branch.initSession and [BranchScene scene:continueUserActivity:] for accessing preference variables. It happens only if both functions are called at the very same time.
Following is the sequence of events which happens

  1. Session initialization starts from function DidFinishLaunching using branch.initSession. It has no universal_link in request. First Open Request is sent to server.
  2. In the meantime - [BranchScene scene:continueUserActivity:] is called and it has universal_link url . It sets this value in prefs. So when First open request is going out - it checks if its a linking request (by checking url in prefs, which is just set by second request), function returns - YES.
  3. After First request is processed - it clears this url from prefs. Now when second Open request is sent - although request params have universal_link_url but its not anymore in prefs - its considered a non-linking request.

Fix : isLinkingRelatedRequest function will read values of identifiers from post params of request instead of preferences.

-- SDK keeps sending archived opens from the previous launch even after link is resolved

Fix : A property is added in BranchOpenRequest class to find out if the event is from the archived queue. Another property processArchivedOpens is added in BNCServerRequestQueue to signal if archived opens should be propecessed.
After SDK gets referringURL in BranchOpenRequest response, it turns of this flag.

processNextQueueItem function uses these properties to find out if the next request is from archive and it should not be processed. If YES, it removes it from the queue and processes next one.

-- SDK resets session using enum variable initializationStatus. It sets its value to BNCInitStatusUninitialized. Its a global variable and its value is sometimes changed by other parallel session initializations happening, if any, to BNCInitStatusInitializing or BNCInitStatusInitialized. So function initUserSessionAndCallCallback, which checks this value for session initialization, simply returns wihtout resetting/initializing session.

Fix : Added param in function initUserSessionAndCallCallback for forced session re-initialization irrespective of current SDK initializationStatus

Testing Instructions

Use a test app with Universal Link Enabled and tracking disabled.

--> If Test App is running kill it. Cold Launch is required.
--> Copy universal links for testing in iMessage.
--> Click on Univesal Links in iMessage.
--> Test App should be launched.
--> Check logs to see if Open request sent with param "universal_link_url" is processed and other opens without this params are dropped.

Repeat this test multiple times, by killing app and re-launching app using links from iMessage.

I have used this app https://github.com/BranchMetrics/SpotifyTest

Links used for testing -

https://cq9pf.app.link/FoVf9M9bDLb

https://cq9pf.app.link/fSMdfpldDLb

https://cq9pf.app.link/TfySwxRdDLb

Repeat test by enabling tracking as well as delaying function calls initSession and BranchScene.shared().scene(...)

Type Of Change

  • Bug fix (non-breaking change which fixes an issue)

cc @BranchMetrics/saas-sdk-devs for visibility.

-> Moved check isLinkingRelatedRequest to postRequest func
-> Fixed isLinkingRelatedRequest to read identifiers from request post params.
-> Temporarily Commented out code for retrieving archived queues - will revert later
…sion re-initialization irrespective of current SDK initializationStatus
@@ -1971,8 +1981,9 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr

dispatch_async(self.isolationQueue, ^(){


// If the session is not yet initialized
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment on this line that reset means we've got a new link we need to process

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or whatever reset specifically indicates

@NidhiDixit09 NidhiDixit09 merged commit 74c40ad into master Aug 2, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants