How to integrate UserEcho support portal with mobile application - iOS example

Последнее изменение:


Below is complete example how to integrate UserEcho into your iOS mobile application.


All code in this example will use swift language.


We will use WKWebView component. An object that displays interactive web content, such as for an in-app browser.

Step-1

  1. Open the XIB or Storyboard you want to add the web view to in Interface Builder
  2. Find the web view or WKWebView in the Object Library at the bottom-left of Interface Builder
  3. Drag-and-drop a WKWebView object from the Object Library to your view controller’s canvas, and adjust its size and position

Step-2 URLRequest

First, we’ll create an instance of URLRequest with the information about the URL we want to load. Like this:

let request = URLRequest(url: URL(string: "https://support.userecho.ru")!)

Step-3 Android WebView loadUrl

Next, we’ll use this request to load the URL in the webview. Like this:

webView?.load(request)

Step-4 Adding support for authorization using Google

Without this modifications, you can get following message if you try authorize in the UserEcho via Google.

Error 403: disallowed_useragent
Google can't sign in safely inside this app. You can use Google sign-in by visiting this app's website in a browser like Safari or Chrome. 

To avoid this remove let set  UserAgent to something more real.

 override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        
        webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"
        
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }

The whole code example

ViewController.swift

//
//  ViewController.swift
//  UserEcho Demo
//

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {
    
 var webView:WKWebView!
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        
        webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"
        
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let request = URLRequest(url: URL(string: "https://support.userecho.ru")!)

        webView?.load(request)
    }


}

Эта статья была полезна для 4 людей. Эта статья помогла вам?