I am facing an issue where the deep link navigation does not work when the app is killed, it works fine when the app is either active or in the background. MoEngage React Native SDK version I’m currently using is 9.1.0
From what I understand a deeplink should be obtained via Linking.getInitialURL()
. While it partly works for Android (but the link can’t be used as is), it doesn’t work at all for iOS
The workaround I’m currently using is:
// MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
val originalIntent = intent
if (originalIntent.extras != null) {
val remoteMessage = RemoteMessage(originalIntent.extras)
if (MoEPushHelper.getInstance().isFromMoEngagePlatform(remoteMessage.data)) {
try {
val deeplink = remoteMessage.data[PUSH_NOTIFICATION_NAVIGATION_DEEPLINK]
?: remoteMessage.data[PUSH_NOTIFICATION_NAVIGATION_DEEPLINK_LEGACY]
if (deeplink != null) {
originalIntent.apply {
data = Uri.parse(deeplink)
}
intent = originalIntent
}
} catch (e: Exception) {
// Handle exception
}
}
}
super.onCreate(null)
}
// AppDelegate.mm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Other initializations
NSMutableDictionary *newLaunchOptions = [NSMutableDictionary dictionaryWithDictionary:launchOptions];
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo && !launchOptions[UIApplicationLaunchOptionsURLKey]) {
if ([[MoEngageSDKMessaging sharedInstance] isPushFromMoEngageWithPayload:userInfo]) {
NSString *initialURL = userInfo[@"app_extra"][@"moe_deeplink"];
if (initialURL) {
newLaunchOptions[UIApplicationLaunchOptionsURLKey] = [NSURL URLWithString:initialURL];
}
}
}
BOOL result = [super application:application didFinishLaunchingWithOptions:newLaunchOptions];
UIView *rootView = self.window.rootViewController.view;
[RNSLoadingView setupWithRootView:rootView];
return result;
}
And then on JS side the link becomes available using Linking.getInitialURL()
While these workarounds solve the issue, I’m wondering if there are better ways to handle it? Thank you!
dwnste is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.