SMC SDK for React Native: https://github.com/salesforce-marketingcloud/react-native-marketingcloudsdk
I'm trying to use deep links with in-app messages but I'm not getting them to work. After receiving the in-app message, I press a button that has a deep link configured on the Marketing Cloud and the message gets simply closes. The expected result is to be redirected to a screen but it doesn't redirect anywhere in the app.
I wonder if anyone was able to configure deep links with in-app messages in React Native.
Is there any extra configuration needed that is missing in the MarketingCloud SDK documentation for React Native?
Deep links are configured correctly on Android and iOS as they were previously independently tested.
More info:
I created the in-app message in the content builder section. The in-app message has two buttons that contain deep links of the form appschema://screen
which after pressing them should redirect to a screen. This event should be detected with the React Native Linking API, that is, at the JavaScript level, but no event is detected, even in native code.
Following you can find the code:
#import "AppDelegate.h"
#import "ReactNativeConfig.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTLinkingManager.h>
#import "RNSplashScreen.h"
#import <Firebase.h>
#import <RNCPushNotificationIOS.h>
#import <UserNotifications/UserNotifications.h>
#import <MarketingCloudSDK/MarketingCloudSDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"appname"
initialProperties:nil];
[FIRApp configure];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[RNSplashScreen showSplash:@"LaunchScreen" inRootView:rootView];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
// Configure the Salesforce Marketing Cloud SDK
MarketingCloudSDKConfigBuilder *mcsdkBuilder = [MarketingCloudSDKConfigBuilder new];
[mcsdkBuilder sfmc_setApplicationId:[ReactNativeConfig envFor:@"MC_APP_ID"]];
[mcsdkBuilder sfmc_setAccessToken:[ReactNativeConfig envFor:@"MC_ACCESS_TOKEN"]];
[mcsdkBuilder sfmc_setAnalyticsEnabled:@(YES)];
[mcsdkBuilder sfmc_setMarketingCloudServerUrl:[ReactNativeConfig envFor:@"MC_APP_SERVER_URL"]];
NSError *error = nil;
BOOL success =
[[MarketingCloudSDK sharedInstance] sfmc_configureWithDictionary:[mcsdkBuilder sfmc_build]
error:&error];
if (success == YES) {
dispatch_async(dispatch_get_main_queue(), ^{
if (@available(iOS 10, *)) {
// set the UNUserNotificationCenter delegate - the delegate must be set here in
// didFinishLaunchingWithOptions
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
[[UIApplication sharedApplication] registerForRemoteNotifications];
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:UNAuthorizationOptionAlert |
UNAuthorizationOptionSound |
UNAuthorizationOptionBadge
completionHandler:^(BOOL granted, NSError *_Nullable error) {
if (error == nil) {
if (granted == YES) {
dispatch_async(dispatch_get_main_queue(), ^{
});
}
}
}];
} else {
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
UIUserNotificationSettings *settings = [UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound |
UIUserNotificationTypeAlert
categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
#endif
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
});
} else {
// MarketingCloudSDK sfmc_configure failed
os_log_debug(OS_LOG_DEFAULT, "MarketingCloudSDK sfmc_configure failed with error = %@",
error);
}
return YES;
}
- (void)sfmc_handleURL:(NSURL *)url type:(NSString *)type {
NSLog(@"Handling open direct url coming from Marketing Cloud");
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSDictionary *dict = [NSDictionary dictionary];
[appDelegate application:[UIApplication sharedApplication] openURL:url options:dict];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
[[MarketingCloudSDK sharedInstance] sfmc_setDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
[[MarketingCloudSDK sharedInstance] sfmc_setNotificationUserInfo:userInfo];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
[RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// IOS 10+ Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler
{
[RNCPushNotificationIOS didReceiveNotificationResponse:response];
[[MarketingCloudSDK sharedInstance] sfmc_setNotificationRequest:response.notification.request];
completionHandler();
}
// IOS 4-10 Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[RNCPushNotificationIOS didReceiveLocalNotification:notification];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
os_log_debug(OS_LOG_DEFAULT, "url = %@", url);
return [RCTLinkingManager application:application openURL:url options:options];
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
@end
React Native side:
Linking.getInitialURL().then(url => {
// This is not executed
// Handle url;
});
Linking.addEventListener('url', ({ url }) => {
// This is not executed
// Handle url;
});
AppDelegate.m
file, hope this can help me to figure out what is going on