1

I'm currently implementing the Marketing Cloud SDK for Push Notification on iOS and I've run into a problem. I've implemented the URL Handling for OpenDirect as per the example provided in documentation (https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/sdk-implementation/implementation-urlhandling.html) but it doesn't work. I'm receiving the following error:

URL was NOT handled - the URL handling delegate method was NOT implemented or delegate nilfile:MarketingCloudSDKFoundation.mline:line: 1641`

I know the error appears when you have not declared setURLHandlingDelegate() or the URLHandlingDelegate protocol but I have them in the code:

import SFMCSDK
import MarketingCloudSDK
/*
 * Please check https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/get-started/get-started-migration.html
 * if you get error: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
 */
final class MarketingCloudService {
    static let shared: MarketingCloudService = MarketingCloudService()
    var isReady: Bool {
        SFMCSdk.mp.getStatus() == .operational
    }
    func setProfileId(_ id: String) {
        SFMCSdk.identity.setProfileId(id)
    }
    func setDeviceToken(token: Data) {
        SFMCSdk.mp.setDeviceToken(token)
        Log("MarketingCloudSDK device token: \(String(describing: SFMCSdk.mp.deviceToken()))")
    }
    func setNotificationUserInfo(_ info: [AnyHashable : Any]) {
        SFMCSdk.mp.setNotificationUserInfo(info)
    }
    func setNotificationRequest(_ request: UNNotificationRequest) {
        SFMCSdk.mp.setNotificationRequest(request)
    }
    func configureSDK() {
        // Enable logging for debugging early on. Debug level is not recommended for production apps, as significant data
        // about the MobilePush will be logged to the console.
        SFMCSdk.setLogger(logLevel: Config.isDebug ? .debug : .error)
        // Use the Mobile Push Config Builder to configure the Mobile Push Module. This gives you the maximum flexibility in SDK configuration.
        // The builder lets you configure the module parameters at runtime.
        if let url = URL(string: Constants.APP_ENDPOINT) {
            let mobilePushConfiguration = PushConfigBuilder(appId: Constants.APP_ID)
                .setAccessToken(Constants.ACCESS_TOKEN)
                .setMarketingCloudServerUrl(url)
                .setMid(Constants.MID)
                .setInboxEnabled(false)
                .setLocationEnabled(false)
                .setAnalyticsEnabled(true)
                .setDelayRegistrationUntilContactKeyIsSet(true)
                .build()
            // Set the completion handler to take action when module initialization is completed. The result indicates if initialization was sucesfull or not.
            // Seting the completion handler is optional.
            let config = ConfigBuilder()
                .setPush(config: mobilePushConfiguration,
                         onCompletion: { [weak self] result in
                    if result == .success {
                        // module is fully configured and ready for use
                        self?.setupMobilePush()
                    }
                })
                .build()
            // Once you've created the mobile push configuration, intialize the SDK.
            SFMCSdk.initializeSdk(config)
        }
    }
    private func setupMobilePush() {
        SFMCSdk.mp.setURLHandlingDelegate(self)
        DispatchQueue.main.async {
            if !UIApplication.shared.isRegisteredForRemoteNotifications {
                UIApplication.shared.registerForRemoteNotifications()
            }
        }
    }
}
extension MarketingCloudService: URLHandlingDelegate {
    // Implement the protocol method and have iOS handle the URL itself
    func sfmc_handle(_ url: URL, type: String) {
        Log("MarketingCloudService handle url: \(url.absoluteString) of type: \(type)")
        // Very simply, send the URL returned from the MobilePush SDK to UIApplication to handle correctly.
        if UIApplication.shared.canOpenURL(url) == true {
            UIApplication.shared.open(url, options: [:],
                                      completionHandler: { (success) in
                Log("Open \(url): \(success)")
            })
        }
    }
}

The sfmc_handle() is never called, the log lines found inside the method are not displayed in the Log. The Log tells me that the notification is received and at the end it states that is not a CloudPage so it's not hadnled (I don't want to use CLoudPages)

[NotificationService.swift, in userNotificationCenter(_:didReceive:withCompletionHandler:) at line: 130]: {
    "_h" = "xnU9iv+XXXXXXXX";
    "_m" = XXXXXXXX;
    "_mt" = 1;
    "_od" = "https://tazzing.ro";
    "_r" = "XXXXXXXX";
    "_sid" = SFMC;
    aps =     {
        alert =         {
            body = "bla bla";
            title = "tazzing link test";
        };
        "mutable-content" = 1;
        sound = default;
    };
}
2022-01-11 15:44:41.888243+0200 tazzing[654:118004] [module] log: `setNotificationRequest = <UNNotificationRequest: 0x281396d60; identifier: 7d7e1fcd-6b38-4757-b1c8-d7cc8f7fe677, content: <UNNotificationContent: 0x282604410; title: <redacted>, subtitle: (null), body: <redacted>, summaryArgument: (null), summaryArgumentCount: 0, categoryIdentifier: , launchImageName: , threadIdentifier: , attachments: (
), badge: (null), sound: <UNNotificationSound: 0x28361f870>, realert: 0, trigger: <UNPushNotificationTrigger: 0x281f158d0; contentAvailable: NO, mutableContent: YES>>` file: `MarketingCloudSDKNotification.m` line: `line: 170`
2022-01-11 15:44:41.906277+0200 tazzing[654:118004] [module] log: `Notification received with userInfo {
    "_h" = "xnU9iv+XXXXXXXX";
    "_m" = XXXXXXXX;
    "_mt" = 1;
    "_od" = "https://tazzing.ro";
    "_r" = "XXXXXXXX";
    "_sid" = SFMC;
    aps =     {
        alert =         {
            body = "bla bla";
            title = "tazzing link test";
        };
        "mutable-content" = 1;
        sound = default;
    };
}` file: `MarketingCloudSDKOpenDirectMessage.m` line: `line: 93`
2022-01-11 15:44:41.906537+0200 tazzing[654:118004] [module] log: `URL https://tazzing.ro was NOT handled - the URL handling delegate method was NOT implemented or delegate nil` file: `MarketingCloudSDKFoundation.m` line: `line: 1641`
2022-01-11 15:44:41.906749+0200 tazzing[654:118004] [module] log: `Notification received with userInfo {
    "_h" = "xnU9iv+XXXXXXXX";
    "_m" = XXXXXXXX;
    "_mt" = 1;
    "_od" = "https://tazzing.ro";
    "_r" = "XXXXXXXX";
    "_sid" = SFMC;
    aps =     {
        alert =         {
            body = "bla bla";
            title = "tazzing link test";
        };
        "mutable-content" = 1;
        sound = default;
    };
}` file: `MarketingCloudSDKCloudPageMessage.m` line: `line: 94`
2022-01-11 15:44:41.906921+0200 tazzing[654:118004] [module] log: `Notification with userInfo {
    "_h" = "xnU9iv+XXXXXXXX";
    "_m" = XXXXXXXX;
    "_mt" = 1;
    "_od" = "https://tazzing.ro";
    "_r" = "XXXXXXXX";
    "_sid" = SFMC;
    aps =     {
        alert =         {
            body = "bla bla";
            title = "tazzing link test";
        };
        "mutable-content" = 1;
        sound = default;
    };
} is not a CloudPage - handler takes no action` file: `MarketingCloudSDKCloudPageMessage.m` line: `line: 115`

What's happening here? It's something wrong with my code?

Any idea is appreciated.

Thank you!

2 Answers 2

1

Please log a support ticket. There is a known bug for this issue. Logging a support ticket will help us track who was affected, and the support person can track the bug and alert you immediately when the fix is released.

2
  • 1
    I've suspected this to be a bug so I did just that: Opened a ticked at support! They keep telling me that is no bug and that is my code at fault. Do you have a record or information on this being a bug? I couldn't find anything on the internet. Thanks!
    – Alex
    Commented Jan 20, 2022 at 16:06
  • 2
    Please ask the support rep to reach out to me - I will reference them to the known issue already logged. Commented Jan 20, 2022 at 16:25
0

This is not a bug in the SDK, but was resolved in the following way

MarketingCloudService is a Swift class and cannot be called from the SDK. It must be changed to an Objective-C compliant class as shown below.

@objc class MarketingCloudService: NSObject, URLHandlingDelegate {
    
    func sfmc_handle(_ url: URL, type: String) {
        
    }
}

If you cannot inherit NSObject, you can write a bridge class like this.

class MarketingCloudService {

    @objc class URLHandler: NSObject, URLHandlingDelegate {

    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .