gpt4 book ai didi

iOS swift : can't Retrieve current url loaded in UIwebView

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:10 25 4
gpt4 key购买 nike

我正在 iOS swift webview 应用程序中工作:

我面临的问题是我想获取 webview 显示的每个 url:

在 url 上我必须执行一些 if else 检查。但我无法获取 webview 加载的 url。

webview 显示良好的结果并在单击时加载 url。我想获取 webview 导航的所有 url..

import Foundation
import UIKit


class seconVC: UIViewController {

var toPass:String!
var touser:String!
var toPassing:String!



@IBOutlet weak var webV: UIWebView!

@IBOutlet weak var L_back: UIBarButtonItem!

@IBOutlet weak var R_frwrd: UIBarButtonItem!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

var domurl = toPass;

var username = touser;

var passwing = toPassing;



var sendurl = stringA+username+"/"+passwing;

//exchange login with auth/username/password
println(sendurl);

let url = NSURL (string: sendurl);


let requestObj = NSURLRequest(URL: url!);
webV.userInteractionEnabled = true
webV.loadRequest(requestObj);



}

@IBAction func L_back(sender: UIBarButtonItem) {

if (webV.canGoBack){
webV.goBack()
}


}

@IBAction func R_frwrd(sender: UIBarButtonItem) {

if (webV.canGoForward){
webV.goForward()
}

}



override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.


}



}

我想要的只是获取 webview 的当前 url 和导航按钮的字符串:请帮忙?我引用了所有互联网,但没有任何解决方案适用于我的情况。

最佳答案

有几个 UIWebViewDelegate,例如 shouldStartLoadWithRequestwebViewDidStartLoadwebViewDidFinishLoaddidFailLoadWithError,帮助您实现目标。如果你想在 View 完成后执行操作,那么实现这个委托(delegate)方法

swift 3

if let currentURL = webView.request?.url?.absoluteString{
print(currentURL)
}

正如它提到的here .

关于iOS swift : can't Retrieve current url loaded in UIwebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38765839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com