Skip to content

feat(EMT-2878): integrate modern SessionManager with async/await#15

Open
wpinho-branch wants to merge 11 commits intogptdriver/linkingTestsfrom
feat/EMT-2878-v4
Open

feat(EMT-2878): integrate modern SessionManager with async/await#15
wpinho-branch wants to merge 11 commits intogptdriver/linkingTestsfrom
feat/EMT-2878-v4

Conversation

@wpinho-branch
Copy link

Summary

Integrate the new Swift SessionManager into BranchLinkSimulator to test the modern async/await API with task coalescing for Double Open prevention (INTENG-21106).

Changes

SPM Integration

  • Remove prebuilt BranchSDK.xcframework reference
  • Add local SPM package reference to ../ios-branch-deep-linking-attribution
  • Configure BranchSDK package product dependency

Modern SessionManager Integration

  • Add BranchSwiftSDK import for SessionManager access
  • Use BranchSessionCoordinator.shared.sessionManager for modern API
  • Replace callback-based initSession with async/await initialize(options:)
  • Implement state observation via AsyncStream<SessionState>
  • Update Universal Links and URL Scheme handlers to use SessionManager

Technical Details

The new SessionManager provides:

  • Task coalescing: Multiple concurrent initialize() calls are merged into a single API request
  • Async/await API: Modern Swift concurrency patterns
  • Actor-based thread safety: Full Swift 6 concurrency compliance
  • AsyncStream observation: Reactive state updates for UI

Testing

  • App launches successfully
  • Session initializes correctly
  • Deep links are handled
  • Universal links are handled
  • State updates are reflected in UI

Related: EMT-2878, INTENG-21106

- Remove conflict markers from .gitignore
- Keep xcodeproj tracked (not ignored)
- Comment out SPM-related ignores to allow project tracking
Replace callback-based Branch initialization with the new Swift
SessionManager that provides task coalescing for Double Open prevention.

Changes:
- Add BranchSwiftSDK import for SessionManager access
- Add sessionState property to DeepLinkViewModel for UI observation
- Create BranchSessionCoordinator reference for modern API access
- Implement initializeWithModernSessionManager using async/await
- Add observeSessionState using AsyncStream for reactive state updates
- Update handleSessionInitialized to convert Session to legacy params
- Refactor Universal Links handler to use SessionManager
- Refactor URL Scheme handler to use SessionManager
- Use SessionState.description for human-readable state display

The new SessionManager provides:
- Task coalescing (prevents duplicate API calls)
- Async/await API (modern Swift patterns)
- Actor-based thread safety (Swift 6 concurrency)
- AsyncStream state observation (reactive updates)
…leState

Remove manual session state management from app - now handled by SDK.

Changes:
- Remove @published sessionState from DeepLinkViewModel
- Remove observeSessionState() method and Task loop
- Add documentation comments for SDK's BranchObservableState usage

The SDK now provides BranchObservableState (ObservableObject) that can be
used directly in SwiftUI views via:
  @ObservedObject var branchState = BranchSessionCoordinator.shared.observableState

This eliminates the need for apps to manually bridge AsyncStream to @published.
…er usage

- Update onOpenURL to use SessionManager instead of legacy Branch.handleDeepLink()
- Use InitializationOptions builder pattern (SDK's .with(launchOptions:))
- Add handleSessionForUI() method for centralized UI updates
- Add @mainactor to initializeWithModernSessionManager for builder pattern
- Import BranchSwiftSDK in BranchLinkSimulatorApp for SessionManager access

This ensures task coalescing works correctly across all entry points:
- didFinishLaunchingWithOptions
- continueUserActivity (Universal Links)
- application:open:options: (URL Schemes)
- onOpenURL (SwiftUI)
- Configure DefaultBranchNetworkService.logCallback in AppDelegate
- Add processSwiftNetworkLog method to RoundTripStore
- Now displays network requests from the new Swift SessionManager
Replace callback-based logging (DefaultBranchNetworkService.logCallback) with
modern Swift Concurrency using AsyncStream:

- Add logObserverTask property to manage the async observation lifecycle
- Implement startNetworkLogObserver() using for-await pattern
- Add processNetworkLogEntry() with @mainactor isolation for thread safety
- Add deinit to properly cancel the observer task

Benefits:
- Eliminates race conditions (AsyncStream buffers logs until observer attaches)
- Uses reactive for-await processing instead of imperative callbacks
- Thread-safe via Actor isolation
- Automatic lifecycle management
…ted logging

- Use SessionManager.shared for SDK initialization
- Consolidate logging to single Branch.enableLogging(at:callback:) call
- Remove redundant BranchLogObserver setup
- Process network logs via RoundTripStore for API debugging
- Handle deep links via SessionManager.handleDeepLink()

The Modern SessionManager provides:
- Task coalescing to prevent "Double Open" issue
- Async callback API for session initialization
- Deep link data via Session.params dictionary
BranchLinkSimulatorApp:
- Clean up app entry point
- Proper environment object injection

HomeView:
- Update logging calls to use BranchLogger.shared()
- Simplify event sending and link creation
- Remove unused code
- Remove BranchSwiftSDK dependency (module no longer exists)
- Replace SessionManager.shared with Branch.getInstance()
- Use initSession(launchOptions:) instead of Swift SessionManager
- Use handleDeepLink(url) for universal links and URL schemes
- Remove unused processSwiftNetworkLog method from RoundTripStore

The Swift SessionManagement layer was removed from BranchSDK as
unnecessary complexity. This update uses the standard Objective-C
SDK methods directly.
…d safety

- Use explicit parameter labels for enableLogging(at:withAdvancedCallback:)
  and initSession(launchOptions:andRegisterDeepLinkHandler:)
- Add [weak self] capture to SDK callbacks to prevent retain cycles
- Dispatch deepLinkViewModel updates to main thread (errorItem,
  deepLinkData, deepLinkHandled) to avoid @published mutation off main
…dition

- Replace NavigationView with NavigationStack (deprecated in iOS 16)
- Replace NavigationLink(isActive:) with navigationDestination(isPresented:)
- Fix QR code sheet showing "No QR Code Available" on first tap by
  removing separate showingQRSheet state and driving sheet presentation
  directly from qrCodeImage via computed Binding
- Rename event callback parameter from result to success to match ObjC API
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.

1 participant