获取 - 通过 UIWebView SWIFT 来自 URL 的响应
Get - response from URL via UIWebView SWIFT
我正在尝试学习 IOS 编程,真正的第一步,但找不到 Swift 我的问题的完整 class 代码示例。
正在加载网页,但我从未收到响应。
这显然是 "extension" 部分的东西,我可能不需要委托
import UIKit
class VkLoginViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
var delegate:UIWebViewDelegate!
override func viewDidLoad() {
super.viewDidLoad()
let link = String.localizedStringWithFormat("http://api.vk.com/oauth/authorize?client_id=%@&scope=email,photos,offline&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token", Setup.VK_AUTH_SCHEME)
NSLog(link)
delegate = self
UIWebView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: link)!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension VkLoginViewController : UIWebViewDelegate{
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let str = request.URL?.absoluteString
NSLog(str!)
return true
}
}
我从来没有收到第二个 NSLog 的消息
将您的代码修改为
class VkLoginViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let link = String.localizedStringWithFormat("http://api.vk.com/oauth/authorize?client_id=%@&scope=email,photos,offline&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token", Setup.VK_AUTH_SCHEME)
NSLog(link)
webView.delegate = self
webView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: link)!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension VkLoginViewController : UIWebViewDelegate{
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let str = request.URL?.absoluteString
NSLog(str!)
return true
}
}
希望对您有所帮助
我正在尝试学习 IOS 编程,真正的第一步,但找不到 Swift 我的问题的完整 class 代码示例。 正在加载网页,但我从未收到响应。 这显然是 "extension" 部分的东西,我可能不需要委托
import UIKit
class VkLoginViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
var delegate:UIWebViewDelegate!
override func viewDidLoad() {
super.viewDidLoad()
let link = String.localizedStringWithFormat("http://api.vk.com/oauth/authorize?client_id=%@&scope=email,photos,offline&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token", Setup.VK_AUTH_SCHEME)
NSLog(link)
delegate = self
UIWebView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: link)!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension VkLoginViewController : UIWebViewDelegate{
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let str = request.URL?.absoluteString
NSLog(str!)
return true
}
}
我从来没有收到第二个 NSLog 的消息
将您的代码修改为
class VkLoginViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let link = String.localizedStringWithFormat("http://api.vk.com/oauth/authorize?client_id=%@&scope=email,photos,offline&redirect_uri=http://api.vk.com/blank.html&display=touch&response_type=token", Setup.VK_AUTH_SCHEME)
NSLog(link)
webView.delegate = self
webView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: link)!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension VkLoginViewController : UIWebViewDelegate{
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
let str = request.URL?.absoluteString
NSLog(str!)
return true
}
}
希望对您有所帮助