Integrate the Android SDK
Runtime Toggles
Enable iOS Push Notifications
Customize Sounds
Display Interactive Notifications
Send Rich Notifications
Handle URLs
Integrate with Other Platforms
Handle URLs
Changelog
The SDK doesn’t automatically present URLs from these sources:
UITableView delegateTo handle URLs from these sources, follow these steps.
URLHandlingDelegate protocol in your app.setURLHandlingDelegate method to set a delegate for the protocol.sfmc_handleURL:type:When an OpenDirect or CloudPages push notification is received, the SDK 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, the class that implements the URLHandlingDelegate must be compatible with Objective-C. Prefix the class with @objc and extend NSObject, as shown in this example.
Important
1// Framework import
2import SFMCSDK
3import PushFeatureSDK
4
5// Make sure your class adopts the protocol
6@objc class MyClass: NSObject, URLHandlingDelegate
7
8...
9// Set the delegate somewhere in your application code (after configuring the SDK)
10 PushFeature.requestSdk { pushFeature in
11 pushFeature?.setURLHandlingDelegate(self)
12 }
13...
14
15// EXAMPLE IMPLEMENTATIONS
16// Implement the protocol method and have iOS handle the URL itself
17func sfmc_handleURL(_ url: URL, type: String) {
18 if UIApplication.shared.canOpenURL(url) == true {
19 if #available(iOS 10.0, *) {
20 UIApplication.shared.open(url, options: [:], completionHandler: { success in
21 if success {
22 print("url \(url) opened successfully")
23 } else {
24 print("url \(url) could not be opened")
25 }
26 })
27 } else {
28 if UIApplication.shared.openURL(url) == true {
29 print("URL \(url) opened successfully")
30 } else {
31 print("Couldn't open URL \(url)")
32 }
33 }
34 }
35}
36
37// Implement the protocol method and use SFSafariViewController to present the URL within your application
38func sfmc_handleURL(_ url: URL, type: String) {
39 let safariViewController = SFSafariViewController(url: url)
40 window?.topViewController()?.present(safariViewController, animated: true) {}
41}
42
43// Implement the protocol method and take application-specific actions based on the URL itself
44func sfmc_handleURL(_ url: URL, type: String) {
45 let queryItems = URLComponents(string: url.absoluteString)?.queryItems
46 for item: URLQueryItem? in queryItems ?? [] {
47 // do something in your application based on the parameters in the URL
48 }
49}