1

I'm using the MarketingCloudSDK for iOS (not JB4ASDK) to receive notifications from the Salesforce Marketing Cloud. We're using OpenDirect notifications to deep-link to some screens in our app, which works well as it opens the target screen.

I'm using the delegate function sfmc_handleURL:(NSURL *)url type:(NSString * _Nonnull)type to get the target name and open the appropriate screen. So when the app receives an OpenDirect notification, the delegate function gets called and begins the process of locating the target screen.

The issue here is that even if the user did not tap the notification, the delegate function is still called which kickstarts the process of displaying the target screen. Is there a way to prevent the delegate function from being called if the user did not tap the notification? i.e. do something about OpenDirect only if the user taps the notification.

EDIT:

Adding some code on how I implemented the delegate function to open a screen:

- (void)sfmc_handleURL:(NSURL *)url type:(NSString *)type {

    NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];

    for (NSURLQueryItem *item in components.queryItems) {

        if ([item.name isEqualToString:@"target"]) {

            AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

            [appDelegate openScreen:item.value];

            break;
        }
    }
}
  • 2
    Nothing about the callback (or SDK notification handling) will be triggered unless you call sfmc_setNotificationRequest or sfmc_notificationUserInfo. Are you calling this method directly (perhaps from -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler)? – Brian M. Criscuolo Apr 9 '19 at 12:00
  • @BrianM.Criscuolo I actually do call sfmc_setNotificationRequest in userNotificationCenter: willPresentNotification: withCompletionHandler so that we can automatically record a notification as "opened" when it was received while the app was active. Thanks for pointing that out! – Anna Fortuna Apr 9 '19 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.