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.
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.
Running on iPhone 12 mini with iOS 18.0. Any ideas?
2
Answers
Simple mistake - I had to run the release mode version of my Flutter app first before being able to properly deep link on cold start. On iOS you must run the app in release mode if you want to open it from cold start.
Branchster here, This kind of issue only happens when there is issue in BranchSDK integration. I suggest you to cross-check your Bundle Identifiers,Apple App Prefix, Associate domain and info.plist with Branch Dashboard. Also, Kindly use latest version of Flutter Branch SDK as there where infra-level changed has been done in the new version. Hopefully this will resolve this issue. If the issue persist, please raise a issue on github here – https://github.com/RodrigoSMarques/flutter_branch_sdk/issues or contact here – [email protected]