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 nil
file:
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!