Handle URLs in the SDK for iOS

Control how your app responds to URLs in push notifications and inbox messages by implementing the URL handling protocol. The SDK passes URLs from CloudPages push notifications, OpenDirect push notifications, and inbox messages to your app, but doesn’t automatically present them. Implement the URLHandlingDelegate protocol to open URLs in Safari, display them in your app using SFSafariViewController, or trigger custom app logic based on URL parameters.

To implement URL handling, follow these steps.

  1. Implement the URLHandlingDelegate (v8.x) or MarketingCloudSDKURLHandlingDelegate (v7.x) protocol in your app.
  2. Use setURLHandlingDelegate (v8.x) or sfmc_setURLHandlingDelegate: method to set a delegate for the protocol.
  3. Implement the protocol method sfmc_handleURL:type:.

When the SDK receives an OpenDirect or CloudPages push notification, it passes a NSURL value to sfmc_handleURL:type:. This value contains the push notification or inbox message, and includes the URL. A type value also reflects the source of the URL, which is either SFMCURLTypeCloudPages or SFMCURLTypeOpenDirect.

If the development language is Swift, make the class that implements URLHandlingDelegate in version 8 or later or MarketingCloudSDKURLHandlingDelegate in version 7 Objective-C compatible. To make the delegate compatible, prefix the class with @objc and extend NSObject, as shown in these examples.

This code example shows how to handle URLs using version 10 or higher of the SDK.

For version 8.1 of the SDK, use this code.

For version 8.0 of the SDK, use this code.

For version 7 of the SDK, use this code.