有人可以帮我解决如何在UIWebView收到的网址中获取查询字符串参数的过程。
@IBOutlet weak var mywebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL (string: "my api url")
let requestObj = NSURLRequest(URL: url!);
mywebView.loadRequest(requestObj)
}
func webViewDidFinishLoad(webView: UIWebView) {
let loadedURL = webView.request?.URL?.absoluteString
print(loadedURL) //prints: http://www.example.com/index.php?key1=value1&key2=value2
}
我如何过滤Key1或Key2值?
谢谢
答案 0 :(得分:0)
使用此
let str = “Your query string text” which you get from url
let pageHtml = NSString(format:"%@ %@", "<html <p style= ><style>body{font-family:'%@'; font-size:17px;}</style></p> </html>",str! as! CVarArg) as String;
self.webView.loadHTMLString(pageHtml,baseURL: nil)
self.webView.loadHTMLString.delegate = self
self.webView.scalesPageToFit = true
self.webView.contentMode = .scaleAspectFit