To redirect users to a specific page or view in your app via push notifications with custom action buttons, you can use deep links. Follow these steps to set up deep linking in your app:
Set Up a URL Scheme
In your Xcode project, define a custom URL scheme (your_deeplink_scheme://).
Configure Info.plist
Open your Info.plist file.
Add a new key: URL types. Xcode will create an array with a dictionary called Item 0.
Inside Item 0, add:
URL identifier> Set it to your custom scheme.
URL Schemes >This creates an array.
Item 0 inside URL Schemes > Set it to your custom scheme.
Handle the Deep Link
Implement the following method in your AppDelegate.swift to handle deep links:
/// Returns who will open the given URL in a push context (e.g. link from web view content).
/// Return `.appHandles` only if you implement `openURL(_:for:)`; otherwise return `.sdkHandles`.
func urlOpeningDecision(for url: URL, push: NetmeraBasePush) -> PushDelegateDecision {
if url.host == "your_domain" || UserDefaults.standard.bool(forKey: NotificationDelegateSetting.deeplinkHandling.rawValue) {
return .appHandles
}
return .sdkHandles
}
/// Called when the delegate has indicated it will open the URL. Open the URL in your preferred way (e.g. in-app browser or deeplink).
func openURL(_ url: URL, for push: NetmeraBasePush) {
print("openURL \(url)")
showAlertInIndependentWindow(title: "App handling link", message: url.absoluteString)
}
}