Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 正在尝试重定向到WKWebView中的url_Ios_Swift - Fatal编程技术网

Ios 正在尝试重定向到WKWebView中的url

Ios 正在尝试重定向到WKWebView中的url,ios,swift,Ios,Swift,我是iOS开发新手,当应用程序通过自定义url(foo://)打开时,我尝试将我的应用程序重定向到特定网站。使用此URL可将我带到AppDelegate中的此处 func application(app: UIApplication, openURL url: NSURL, options:[String: AnyObject]) -> Bool { let viewController = ViewController(); viewController.loadRequ

我是iOS开发新手,当应用程序通过自定义url(foo://)打开时,我尝试将我的应用程序重定向到特定网站。使用此URL可将我带到AppDelegate中的此处

func application(app: UIApplication, openURL url: NSURL, options:[String: AnyObject]) -> Bool {
    let viewController = ViewController();
    viewController.loadRequestExt()
    return true
}   
它调用ViewController中的
loadRequestExt()
函数

func loadRequestExt() {
    super.viewDidLoad()
    self.loadView()
    let url = NSURL (string: "http://www.google.com");
    let requestObj = NSURLRequest(URL: url!);
    self.webView!.loadRequest(requestObj);
    self.loadView()
}

override func loadView() {
    print("loadView")
    super.loadView()

    let contentController = WKUserContentController();
    contentController.addScriptMessageHandler(
        self,
        name: "iOS"
    )

    let config = WKWebViewConfiguration()
    config.userContentController = contentController

    self.webView = WKWebView(
        frame: self.view.frame,
        configuration: config
    )
    self.view = self.webView
    self.webView?.navigationDelegate = self

    // configure the activity view
    activityView.center = self.view.center
    activityView.hidesWhenStopped = true
    activityView.startAnimating()

    self.view.addSubview(activityView)
}

override func viewDidLoad() {
    print("viewDidLoad")

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(registerPushToken), name: "didRegisterForRemoteNotificationsWithDeviceToken", object: nil)

    let url = NSURL (string: "http://charlycares-frontend.herokuapp.com/#/app/login");

    let requestObj = NSURLRequest(URL: url!);
    self.webView!.loadRequest(requestObj);
}

它进入loadView并执行
loadRequest
,但是它保持在同一页面上

您必须将
appdelegate
中窗口属性的
viewcontroller
设置为
rootviewcontroller
(我假设您没有使用情节提要,在这种情况下,您必须将
viewcontroller
设置为初始
viewcontroller
,并且不要将代码添加到
appdelegate
):

ViewController
viewDidLoad
中,调用
loadRequest
函数:

self.loadRequestExt()
self.loadRequestExt()