iOS (Swift)
Check out some examples of how to set up deeplinks and listen for webview redirects in iOS 🍏.
Prerequisites
In order to be able to use the hosted widget in your iOS app, make sure that you:
- Can create access_tokens in your server-side.
- Know how to implement webviews for your platform. For more information, see the webview articles from Apple.
Set up deeplinks in your iOS application
In your Info.plist
file, add the following code:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>[YOUR IDENTIFIER]</string> <!-- Your app name -->
<key>CFBundleURLSchemes</key>
<array>
<string>belvowidget</string> <!-- The Belvo deeplink you need to add. -->
</array>
</dict>
</array>
Handle events in your webview
In the code sample below you can see an example of how to listen and handle for events within your webview.
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
if(navigationAction.navigationType == .other) {
if navigationAction.request.url != nil {
if navigationAction.request.url.host == "success" {
var url = navigationAction.request.url
var link = self.getParameterFrom(url: url, param: "link")
var institution = self.getParameterFrom(url: url, param: "institution")
// Do something with the link and institution.
}
else if navigationAction.request.url.host == "error" {
// If the redirect starts with "error",
// Do something with the error.
}
else {
// If the redirect starts with "exit",
// Do something with the exit information.
}
}
decisionHandler(.cancel)
return
}
decisionHandler(.allow)
}
Updated about 1 year ago
Did this page help you?