iOS
Integration in a 100% native iOS app requires setting up a separate ViewController that contains the WebView where the signup module will show up.
This guide will walk you through setting the WebView app and making sure your app has direct connection to the Signup module and can receive events and data from it.
Create and host an empty html page for loading the Signup module
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Signup</title>
</head>
<body>
<script>
window.onCheckinLoad = (sdk) => {
window.checkin.settings.setLang('en')
sdk.signUp.open()
}
// Listen to module events to be able to close the webview
// when user closes the Signup module
Object.defineProperty(window, 'regilyEventCallback', {
value: function(eventData) {
if (window.webkit.messageHandlers.onEvent) {
window.webkit.messageHandlers.onEvent.postMessage(eventData)
}
}
})
</script>
</body>
</html>
Within window.onCheckinLoad
you should also define your setOnUpdate
and setOnCompleted
methods to handle the user data.
This is done exactly the same way described in the section on handling user data.
Create a new iOS ViewController
Create a new ViewController class called SignupViewController. This should be linked to the view where you want to show the Signup module.
import WebKit
class SignupViewController : UIViewController, WKScriptMessageHandler {
override func viewDidLoad() {
super.viewDidLoad()
// Hide the navigation bar
self.navigationController?.isNavigationBarHidden = true
// Create the webview, setup module events listener, and load the module
let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height))
webView.configuration.userContentController.add(self, name: "onEvent")
self.view.addSubview(webView)
let url = URL(string: "https://[partner].com/ios.html")
webView.load(URLRequest(url: url!))
}
override func viewWillDisappear(_ animated: Bool) {
// Show navigation bar when user leaves this view (closes module)
self.navigationController?.isNavigationBarHidden = false
super.viewWillDisappear(animated)
}
// Handler for Module state events. E.g. open/close
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
if message.name == "onEvent" {
let data = message.body as! Dictionary<String, Any>
switch(data["action"] as! String) {
case "close-module":
self.navigationController?.popViewController(animated: true)
break
default:
break
}
}
}
}
Launch the module with a button tap!
func singupClicked() {
self.navigationController?.pushViewController(SignupViewController(), animated: true)
}
Updated about 2 years ago