I have a problem with an open request in my app. My apps sends a request to a web view and I need to open this request in a browser on a cellphone. I can not get it to open or perform the request in the web browser. when I use the command code only can string format of URL. How I can do request?
I use the command code string format of URL. How I can issue this request?
import UIKit
class PaymentViewController: UIViewController, UIWebViewDelegate {
var delegate: BackProtocol? = nil
var firstCall = true
var providerId: Int!
var transactionId: String!
@IBOutlet weak var webView: UIWebView!
func configureView() {
self.navigationItem.title = LocalizationSystem.sharedInstance.localizedStringForKey(key: "pay" , comment:"")
// back button
self.navigationItem.addCustomButton(style: .action, position: .left, customView: UIView())
if LocalizationSystem.sharedInstance.getLanguage() == "fa" {
self.navigationItem.addBackButtonEnglishLanguage(target: self, selector: #selector(onBackPressed))
} else {
self.navigationItem.addBackButton(target: self, selector: #selector(onBackPressed))
}
self.webView.delegate = self
}
override func viewDidLoad() {
super.viewDidLoad()
self.configureView()
var request = URLRequest(url: URL(string: String(format: "%@%@",
Downloader.API_BASE_URL,
String(format: Downloader.API_PAYMENT_URL, transactionId,
providerId, Statics.CALLBACK_URL)))!)
request.httpMethod = "GET"
request.setValue(UserInfo.acessToken!, forHTTPHeaderField: "Authorization")
self.webView.loadRequest(request)
// guard let url = URL(string: "http://www.google.com") else {
// return //be safe
// }
//
// if #available(iOS 10.0, *) {
// UIApplication.shared.open(url, options: [:], completionHandler: nil)
// } else {
// UIApplication.shared.openURL(url)
// }
}
func webViewDidFinishLoad(_ webView: UIWebView) {
if let requestedUrl = webView.request?.mainDocumentURL?.absoluteString {
let parts = requestedUrl.components(separatedBy: "/")
// return to previous page
if parts[3] == "verify_payment" {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) { // 2 seconds later
self.onBackPressed()
}
}
}
}
}