我无法将请求从func传递到下一个视图。我想将我的请求从VC1传递到VC2,以将其发送到WkWebView。
VC1包含以下代码:
var request = URLRequest(url: payURL!)
request.httpMethod = "POST"
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
let p = String(format: "TotalAmount=%@&Signature=%@&OrderID=%@&Version=%@&PurchaseTime=%@&TerminalID=%@&MerchantID=%@&Currency=%@&locale=%@&PurchaseDesc=%@",
param["TotalAmount"]! as! CVarArg,
param["Signature"]! as! CVarArg,
param["OrderID"]! as! CVarArg,
param["Version"]! as! CVarArg,
param["PurchaseTime"]! as! CVarArg,
param["TerminalID"]! as! CVarArg,
param["MerchantID"]! as! CVarArg,
param["Currency"]! as! CVarArg,
param["locale"]! as! CVarArg,
param["PurchaseDesc"]! as! CVarArg)
request.httpBody = p.data(using: String.Encoding.utf8, allowLossyConversion: true)
let payController = kMainStoryboard.instantiateViewController(withIdentifier: "EVPayControllerViewController") as! EVPayControllerViewController
payController.request = request
navigationController?.present(payController, animated: true, completion: nil)
VC2
class EVPayControllerViewController: UIViewController, WKNavigationDelegate, UIWebViewDelegate {
var request: URLRequest?
let wkWebView = WKWebView()
let webView = UIWebView()
override func viewDidLoad() {
super.viewDidLoad()
print(request?.httpBody) //nil
}
}