RodrigoSMarques / flutter_branch_sdk

Flutter Plugin for create deep link using Branch Metrics SDK. This plugin provides a cross-platform (iOS, Android, Web).
https://branch.io
MIT License
100 stars 91 forks source link

Flutter app crashes on opening deep link from cold state #382

Closed zhpixel517 closed 1 month ago

zhpixel517 commented 1 month ago

Keep the template and provide all requested information:

Describe the bug I recently implemented deep linking with Branch.io for my flutter app running on iOS. It works as expected when the app is running in the background. When the Branch.io link is clicked, it will open in my Flutter app. However, when the app is completely closed and in a cold state, tapping the link will begin to redirect to the application but then the app crashes immediately.

This is my code for creating and opening deep links:

static Future<void> listen(BuildContext context) async {
    await FlutterBranchSdk.init();
    StreamSubscription<Map>? streamSubscription;

    streamSubscription = FlutterBranchSdk.listSession().listen((data) async {
      if (data.containsKey("groupId") && context.mounted) {
        AppNavigationV2.to(
            AppPages.groupProfileScreen, {"data": data["groupId"]});
      }
    }, onError: (error) {
      PlatformException platformException = error as PlatformException;
      print(
          'InitSession error: ${platformException.code} - ${platformException.message}');
    });
  }

  // Following this guide: 
  // https://seayeshaiftikhar.medium.com/branch-io-for-deep-linking-in-flutter-2327530f1639
  static Future<void> createLink(String groupId) async {
    BranchUniversalObject branchUniversalObject = BranchUniversalObject(
        canonicalIdentifier: 'flutter/branch',
        contentMetadata: BranchContentMetaData()
          ..addCustomMetadata('groupId', groupId),);
    FlutterBranchSdk.registerView(buo: branchUniversalObject);
    BranchLinkProperties linkProperties =
        BranchLinkProperties(feature: 'sharing');
    linkProperties.addControlParam('\$uri_redirect_mode',
        '1'); // this will redirect the link to application

    BranchResponse response = await FlutterBranchSdk.getShortUrl(
        buo: branchUniversalObject, linkProperties: linkProperties);
    Share.share(response.result);
  }

I made sure to run FlutterBranchSdk.validateSDKIntegration(); and all the checks passed - my Info.plist file configuration appears to be correct.

Anything look amiss?

I was able to watch my device's output with Mac's Console app, and when the app crashes, I see some error messages like this:

[(FBSceneManager):sceneID:com.myapp.myapp-default] Update failed: <NSError: 0x3038b52f0; domain: FBSceneErrorDomain; code: 1 ("operation-failed"); "Scene update failed."> {
    NSUnderlyingError = <NSError: 0x3026896b0; domain: BSServiceConnectionErrorDomain; code: 3 ("OperationFailed"); "XPC error received on message reply handler">;
}
Process state is unknown AppStateTracker, pid 3533, uuid xxxxxxx-xxxxxxx display identifier com.myapp.myapp foreground 1
COSMCtrl _foregroundAppActivity incoming bundle com.myapp.myapp has nil supplied UUID, finds existing xxxxxxxxx-xxxx-xxx-xxx-xxxxxxxx

I also tried following this solution to no success.

To Reproduce Steps to reproduce the behavior:

  1. Create a deep link with the above code
  2. Close the flutter app completely
  3. Tap the link
  4. See error - the app will crash.

Expected behavior I expected it to open the app!

Screenshots

https://github.com/user-attachments/assets/1b916e40-62bf-467a-9c41-db013059810c

Mobile (Please complete the following information. remove session if not Mobile):

zhpixel517 commented 1 month ago

Turns out it was because the app was in debug mode, not release mode! Running flutter run --release , closing the app, then clicking the link worked.

tkddbf7348 commented 1 month ago

@zhpixel517

hello. In my case, the same phenomenon is seen in the release version as in the video. Is there a solution?