Skip to content

Refactor SKAN related code and BranchOpenRequest Class#1570

Merged
NidhiDixit09 merged 20 commits into4.0.0-alpha.0from
ndixit/EMT-3068
Feb 23, 2026
Merged

Refactor SKAN related code and BranchOpenRequest Class#1570
NidhiDixit09 merged 20 commits into4.0.0-alpha.0from
ndixit/EMT-3068

Conversation

@NidhiDixit09
Copy link
Copy Markdown
Collaborator

Reference

[iOS] Refactor SKAN related code and BranchOpenRequest Class
https://branch.atlassian.net/browse/EMT-3068

Summary

This PR contains no behavioral changes. It has purely structural refactoring to remove duplicate codes and simplify functions for easier testing and debugging.
ReFactored BranchOpenRequest and BranchEvent class to move SKAN related code to BNCSKAdNetwork class.
Moved code out of processResponse function into more focused helper functions.

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

@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 16, 2026

Code Quality type: bug fix

Summary By MatterAI MatterAI logo

🔄 What Changed

This PR executes a significant structural refactor of the Branch iOS SDK. Key changes include moving SKAdNetwork (SKAN) logic from BranchOpenRequest and BranchEvent into the centralized BNCSKAdNetwork class. The processResponse method in BranchOpenRequest was decomposed into focused helper functions like sessionDataFromResponseData:error:. Additionally, the test suite was modernized by switching to @import BranchSDK, removing over 1,000 lines of legacy UI tests, and improving async test stability with waitForExpectations in integration tests.

🔍 Impact of the Change

The refactor significantly reduces technical debt by eliminating duplicate SKAN logic and isolating response processing. Defensive key validation for randomized_device_token prevents potential nil-pointer crashes. The removal of redundant UI tests and the transition to module imports (@import) streamlines the build process and improves developer experience. Integration tests are now more resilient to timing issues.

📁 Total Files Changed

Click to Expand
File ChangeLog
Import Modernization Branch-TestBed/Branch-SDK-Tests/*.m Switched multiple test files to use @import BranchSDK for better module support.
Test Cleanup Branch-TestBed-UITests/*.m Deleted several legacy UI test files (Safari, Identity, Tracking) to reduce maintenance overhead.
App Logic Branch-TestBed/AppDelegate.m Updated imports and added pasteboard check initialization logic.
Test Stability iOSReleaseTestTests.swift Added waitForExpectations to ensure async attribution level tests complete reliably.
Package Config Package.swift Added documentation comments to the main BranchSDK library product.

🧪 Test Added/Recommended

Added

  • Integration Stability: waitForExpectations added to testInitSessionAndSetCPPLevel in both iOS and tvOS release tests to prevent premature test exit.

Recommended

  • Helper Unit Tests: Add specific unit tests for the new sessionDataFromResponseData:error: helper to validate handling of malformed JSON payloads.
  • SKAN Migration Test: Verify that BNCSKAdNetwork correctly receives and processes data previously handled by BranchOpenRequest.

🔒 Security Vulnerabilities

No critical vulnerabilities detected. The implementation of defensive checks for device tokens and synchronized initialization guards in Branch.m (from previous data) enhances the SDK's thread safety and robustness against malformed server responses. 🛡️

⏳ Estimated code review effort

MEDIUM (~20 minutes)

Tip

Quality Recommendations

  1. Ensure the removed UI tests are adequately covered by the remaining unit and integration test suites.

  2. Verify that switching to @import BranchSDK does not break compatibility for consumers using older versions of Xcode without module support enabled.

  3. Consider adding a dedicated test case for the randomizedDeviceToken fallback logic in BranchOpenRequest.

♫ Tanka Poem

Old code finds its rest 💤
SKAN logic moves to its home 🏠
Tests are clean and fast ⚡
Stable paths for every link 🔗
Ship with confidence! 🚀

Sequence Diagram

sequenceDiagram
    participant S as Branch Server
    participant BOR as BranchOpenRequest
    participant SKAN as BNCSKAdNetwork
    participant PH as BNCPreferenceHelper

    S->>BOR: HTTP Response (JSON)
    Note over BOR: processResponse()
    
    BOR->>BOR: sessionDataFromResponseData(data)
    BOR->>BOR: handleSKANWithResponseData(data)
    
    BOR->>SKAN: updateConversionValue(responseData)
    SKAN->>PH: read/write SKAN settings
    
    Note over BOR: Update Session State
Loading

Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: Refactoring looks solid overall, moving SKAN logic to a dedicated class is a good improvement. Found a critical logic issue in randomizedDeviceTokenFromResponseData where the fallback code is unreachable, and a type safety improvement for userIdentityFromResponseData.

Comment thread Sources/BranchSDK/BranchOpenRequest.m
Comment thread Sources/BranchSDK/BranchOpenRequest.m Outdated
Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: The refactoring correctly removes the unreachable code/early return logic identified previously. However, the type safety issue regarding NSNull handling remains unaddressed.

Comment thread Sources/BranchSDK/BranchOpenRequest.m
Copy link
Copy Markdown
Collaborator

@wpinho-branch wpinho-branch left a comment

Choose a reason for hiding this comment

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

Overall the refactoring direction looks great — consolidating SKAN logic into BNCSKAdNetwork and extracting helpers from processResponse makes the code much more readable and testable. Nice work!

A few minor things I noticed:

  1. releaseOpenResponseLock ordering (BranchOpenRequest.m:146) — moved after SKAN handling, which extends the lock scope slightly. See inline comment.
  2. randomizedDeviceTokenFromResponseData: fallback (BranchOpenRequest.m:169) — subtle change in when the deprecated key fallback is attempted. See inline comment.
  3. Commit hygiene — there are duplicate commit messages and a "Test commit" (b4ef55e). Consider squashing before merge for a cleaner history.

None of these are blockers — the core refactoring is solid.

Comment thread Sources/BranchSDK/BranchOpenRequest.m Outdated
Comment thread Sources/BranchSDK/BranchOpenRequest.m
Comment thread Sources/BranchSDK/BranchOpenRequest.m
Comment thread Sources/BranchSDK/BranchOpenRequest.m
- Added API - `- (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level resetSession:(BOOL)resetSession` to provide an option to disable resetting session.
- Remove silent SDK initialization - initSafetyCheck removed.Now APIs will return or log BNCInitError error.
- Added @synchronized(self) around all 5 init status checks to ensure it waits for any in-progress initSession code (which also uses @synchronized(self)) to finish and update the status before evaluating.
@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 20, 2026

✅ Reviewed the changes: Refactoring looks good. Found a few minor issues: a typo in the log messages ('intialize' -> 'initialize') and a convention issue (using true instead of YES in Objective-C).

@NidhiDixit09 NidhiDixit09 changed the base branch from ndixit/remove-swift-configurationcontroller to 4.0.0-alpha.0 February 23, 2026 20:07
Copy link
Copy Markdown
Contributor

@matterai-app matterai-app Bot left a comment

Choose a reason for hiding this comment

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

🧪 PR Review is completed: Refactoring looks good overall, but identified a critical logic error that breaks the fallback mechanism for device tokens.

Comment thread Sources/BranchSDK/BranchOpenRequest.m
@matterai-app
Copy link
Copy Markdown
Contributor

matterai-app Bot commented Feb 23, 2026

✅ Reviewed the changes: The provided changes in the test files and testbed app look good. The addition of @import BranchSDK; and waitForExpectations in the integration tests are appropriate improvements.

@NidhiDixit09 NidhiDixit09 merged commit 3582e57 into 4.0.0-alpha.0 Feb 23, 2026
8 of 10 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