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

INTENG-21106 Fix for double opens #1425

Merged
merged 9 commits into from
Sep 9, 2024

Conversation

NidhiDixit09
Copy link
Collaborator

@NidhiDixit09 NidhiDixit09 commented Aug 29, 2024

Reference

https://branch.atlassian.net/browse/INTENG-21106 - Double Opens Issue

Summary

iOS SDK sends two OPEN requests on cold launch (since Release 3.3 + ) if app is opened by clicking universal link.
First OPEN is sent by API Branch.getInstance().initSessionWithLaunchOptions and second OPEN is from Branch.getInstance().continue(userActivity)
So if app sets a callback while initializing session using API initSessionWithLaunchOptions, this callback will be called twice on cold launch via universal link click.

This behavior came as a side effect to fix - https://github.com/BranchMetrics/ios-branch-deep-linking-attribution/pull/1369/files/2009c84ae1b603d963a5e064c2f5eb7e97f6f242.

This pull request adds back some of the checks removed in above pull requests as well as adds few more.

As per the current state of SDK,initSessionWithLaunchOptions will call send OPEN ( by calling initUserSessionAndCallCallback method ) only if ,
--> There is a URL in push notification OR
--> Deffered init is enabled. OR
--> Universal Link / Cutom URI is NOT expected to come later. (Organic Open)

Motivation

This pull request fixes Double Opens Issue. Issue can be reproduced as described below -

-> Integrate latest iOS SDK with an AppDelegate only app (like device finder app). Other Apps Not Using Scenes

-> Kill app if its already running.

-> Click universal link to launch app again. Check logs. You will find two OPEN requests. If callback is set during intialization, that callback will be called twice.

Type Of Change

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

Testing Instructions

--> Cold Launch an AppDelegate Only app by clicking a universal link and verify only one OPEN request is sent and callback is called only once.(Ignore OPENs called by applicationDidBecomeActive. They dont call callbacks. )
--> On organic opens, single OPEN request is sent.
--> On deferred initialization and cold launch via universal link click, links are resolved. Please refer to this pull request for more details about testing this feature.

@rob-gioia-branch This pull request is related to fix for issue INTENG-20098. So I have tagged you as well for review.

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

initSceneSessionWithLaunchOptions will call initUserSessionAndCallCallback method only is there is a push URL or BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY is true.
In rest of the use cases initUserSessionAndCallCallback will be called by function - handleDeepLink(universal links or custom URIs ) or appDidBecomeActive (organic Opens)
@NidhiDixit09 NidhiDixit09 changed the title [IN PROGRESS] INTENG-21106 Fix for double opens INTENG-21106 Fix for double opens Sep 5, 2024
@nsingh-branch
Copy link
Contributor

@NidhiDixit09 I've been testing with Device ID finder and this branch and it looks like i'm still seeing two v1/open requests when cold opening the app via a universal link.

[BranchSDK][Debug][Branch initializeSessionAndCallCallback:sceneIdentifier:urlString:] Request <BranchOpenRequest: 0x600000206ee0> callback <__NSMallocBlock__: 0x60000173aa80> link (null)
[BranchSDK][Debug][Branch initializeSessionAndCallCallback:sceneIdentifier:urlString:] Link resolution request
[BranchSDK][Debug][Branch initializeSessionAndCallCallback:sceneIdentifier:urlString:] Request <BranchOpenRequest: 0x60000020e980> callback <__NSMallocBlock__: 0x600001730a40> link https://app.deviceidfinder.com/spG6UBLDEMb
[BranchSDK][Debug][BNCServerInterface preparePostRequest:url:key:retryNumber:] <NSMutableURLRequest: 0x6000000185d0> { URL: https://api3.branch.io/v1/open }
Headers {
    "Content-Length" = 1432;
    "Content-Type" = "application/json";
}
Body {
  "anon_id" : "DD2CA51F-D696-41E6-B88D-57CCB67222D5",
  "app_version" : "1.10.4",
  "apple_testflight" : false,
  "branch_key" : "key_live_lmJDv2hI9NuyiSzLNO3UVfmpCAk13Cbt",
  "brand" : "Apple",
  "build" : "22G91",
  "connection_type" : "wifi",
  "country" : "US",
  "cpu_type" : "16777228",
  "debug" : false,
  "environment" : "FULL_APP",
  "first_install_time" : 1715121439838,
  "hardware_id" : "2B9241D6-3F9A-4C71-87A4-3A13F58514AD",
  "hardware_id_type" : "vendor_id",
  "ios_bundle_id" : "com.branch.findDeviceID",
  "ios_vendor_id" : "2B9241D6-3F9A-4C71-87A4-3A13F58514AD",
  "is_hardware_id_real" : true,
  "language" : "en",
  "lastest_update_time" : 1725574462566,
  "latest_install_time" : 1725574091567,
  "local_ip" : "192.168.1.7",
  "locale" : "en_US",
[BranchSDK][Debug][BNCServerInterface processServerResponse:data:error:] <NSHTTPURLResponse: 0x6000002680c0> { URL: https://api3.branch.io/v1/open } { Status Code: 200, Headers {
    "Access-Control-Allow-Origin" =     (
        "*"
    );
    "Cache-Control" =     (
        "no-cache"
    );
    "Content-Length" =     (
        443
    );
    "Content-Type" =     (
        "application/json; charset=utf-8"
    );
    Date =     (
        "Thu, 05 Sep 2024 22:15:22 GMT"
    );
    "Strict-Transport-Security" =     (
        "max-age=31536000; includeSubDomains"
    );
    Via =     (
        "1.1 8fd16721c32269f6a38b6515e2acebe8.cloudfront.net (CloudFront)"
    );
    "x-amz-cf-id" =     (
        "vQwWThPbk_P531GONMS6SN-PFRSwNFCoj02B8hgbPpYk50ITOuIrdQ=="
    );
    "x-amz-cf-pop" =     (
        "SFO5-C3"
    );
    "x-branch-request-id" =     (
        "f6181830-9c29-47b8-ab7b-17184c4742f5-2024090522"
    );
    "x-cache" =     (
        "Miss from cloudfront"
    );
    "x-powered-by" =     (
[BranchSDK][Debug][BranchOpenRequest processResponse:error:] SKAN 4.0 params - conversionValue:2 coarseValue:low, locked:1, shouldCallPostback:0, currentWindow:1, firstAppLaunchTime: 2024-09-05 22:08:13 +0000
[BranchSDK][Debug][BNCServerInterface preparePostRequest:url:key:retryNumber:] <NSMutableURLRequest: 0x60000001c1c0> { URL: https://api3.branch.io/v1/open }
Headers {
    "Content-Length" = 1562;
    "Content-Type" = "application/json";
}
Body {
  "anon_id" : "DD2CA51F-D696-41E6-B88D-57CCB67222D5",
  "app_version" : "1.10.4",
  "apple_testflight" : false,
  "branch_key" : "key_live_lmJDv2hI9NuyiSzLNO3UVfmpCAk13Cbt",
  "brand" : "Apple",
  "build" : "22G91",
  "connection_type" : "wifi",
  "country" : "US",
  "cpu_type" : "16777228",
  "debug" : false,
  "environment" : "FULL_APP",
  "first_install_time" : 1715121439838,
  "hardware_id" : "2B9241D6-3F9A-4C71-87A4-3A13F58514AD",
  "hardware_id_type" : "vendor_id",
  "instrumentation" : {
    "https:\/\/api3.branch.io\/v1\/open-brtt" : "151"
  },
  "ios_bundle_id" : "com.branch.findDeviceID",
  "ios_vendor_id" : "2B9241D6-3F9A-4C71-87A4-3A13F58514AD",
  "is_hardware_id_real" : true,
  "language" : "en",
  "lastest_update_time" : 1725574462566,
  "latest
[BranchSDK][Debug][BNCServerInterface processServerResponse:data:error:] <NSHTTPURLResponse: 0x6000002662a0> { URL: https://api3.branch.io/v1/open } { Status Code: 200, Headers {
    "Access-Control-Allow-Origin" =     (
        "*"
    );
    "Cache-Control" =     (
        "no-cache"
    );
    "Content-Length" =     (
        744
    );
    "Content-Type" =     (
        "application/json; charset=utf-8"
    );
    Date =     (
        "Thu, 05 Sep 2024 22:15:22 GMT"
    );
    "Strict-Transport-Security" =     (
        "max-age=31536000; includeSubDomains"
    );
    Via =     (
        "1.1 8fd16721c32269f6a38b6515e2acebe8.cloudfront.net (CloudFront)"
    );
    "x-amz-cf-id" =     (
        "1jL481tQr45vK2u1DbO6cwdQojmssm7EE8eIx7uKsWxjXhqrS4C6Ug=="
    );
    "x-amz-cf-pop" =     (
        "SFO5-C3"
    );
    "x-branch-request-id" =     (
        "36e85afb-f344-4e54-b940-71b5015b87df-2024090522"
    );
    "x-cache" =     (
        "Miss from cloudfront"
    );
    "x-powered-by" =     (
[BranchSDK][Debug][BranchOpenRequest processResponse:error:] SKAN 4.0 params - conversionValue:2 coarseValue:low, locked:1, shouldCallPostback:0, currentWindow:1, firstAppLaunchTime: 2024-09-05 22:08:13 +0000

@rob-gioia-branch
Copy link
Contributor

Thank you for tagging me for vis @NidhiDixit09! Really excited to let the customer know about this being fixed once the PR is merged + the new version of the SDK is released. Nice work!

@NidhiDixit09 NidhiDixit09 merged commit 800ea81 into master Sep 9, 2024
14 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