import Foundation import KeychainAccess enum APIError : Error { case accessTokenExpired case networkError // Add more error cases as needed } class APIManager { private let keychain = Keychain (service: "com.example.app.refreshToken" ) private let refreshTokenKey = "refreshToken" private var accessToken: String ? func callAPI < T : Codable >( urlString : String , method : String , parameters : [ String : Any ] ? , completion : @escaping ( Result < T , APIError >) -> Void ) { guard let url = URL (string: urlString) else { completion(.failure(.networkError)) return } var request = URLRequest (url: url) request.httpMethod = method // Add access token to the request headers if available if let token = accessToken { request.setValue( "Bearer \(token) " , forHTTPHeaderField: "Aut...
Create a simple Application open web URL in to WKWebView! or open web Browser WKWebView.
iOS Developer Live - There are Two Different Type open url with web view, UIWebView or WKWebView. Before iOS 8.0 Used UIWebView. Now After iOS 8.0 or Later apple introduce A New Claas WKWebView in the Library WebKit. WKWebView faster to fast load webpage and more batter than UIWebView, its do not overload memory.
Example
Add code your ViewController class
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView : WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
// loading URL :
let url = URL(string: studyPlusUrl)
let request = URLRequest(url: url! as URL)
// init and load request in webview.
webView = WKWebView(frame: self.view.frame)
webView.navigationDelegate = self
webView.load(request)
webView.allowsBackForwardNavigationGestures = true
self.view.addSubview(webView)
self.view.sendSubview(toBack: webView)
// left - Right *** Back & Forward app
webView.allowsBackForwardNavigationGestures = true
}
private func webView(webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
print(error.localizedDescription)
}
private func webView(webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
print("Strat to load")
}
private func webView(webView: WKWebView, didFinishNavigation navigation: WKNavigation!) {
print("finish to load")
}
}
Comments
Post a Comment