Swift : 如何打开 URL 应用内
Swift : how to open an URL in-app
我正在使用 OAuthSwift,它运行良好,但是当我单击我的登录按钮时,它会打开一个新的 Safari 页面。我想在应用程序内打开 URL,但我刚开始,不知道该怎么做。
我的代码:
@IBAction func loginButton(sender: AnyObject) {
doOAuthDribbble()
}
func doOAuthDribbble(){
let oauthswift = OAuth2Swift(
consumerKey: Dribbble["consumerKey"]!,
consumerSecret: Dribbble["consumerSecret"]!,
authorizeUrl: "https://dribbble.com/oauth/authorize",
accessTokenUrl: "https://dribbble.com/oauth/token",
responseType: "code"
)
oauthswift.authorizeWithCallbackURL( NSURL(string: "dribs://oauth-callback/dribbble")!, scope: "public+write+comment+upload", state: "", success: {
credential, response in
// Get User
var parameters = Dictionary<String, AnyObject>()
oauthswift.client.get("https://api.dribbble.com/v1/user?access_token=\(credential.oauth_token)", parameters: parameters,
success: {
data, response in
let jsonDict: AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
println(jsonDict)
}, failure: {(error:NSError!) -> Void in
println(error)
})
}, failure: {(error:NSError!) -> Void in
println(error.localizedDescription)
})
}
我的登录页面
然后,新的 Safari 页面
在您的 WebViewController.swift
的 viewDidLoad()
中
myUrl = someurl
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: myUrl)!))
我正在使用 OAuthSwift,它运行良好,但是当我单击我的登录按钮时,它会打开一个新的 Safari 页面。我想在应用程序内打开 URL,但我刚开始,不知道该怎么做。
我的代码:
@IBAction func loginButton(sender: AnyObject) {
doOAuthDribbble()
}
func doOAuthDribbble(){
let oauthswift = OAuth2Swift(
consumerKey: Dribbble["consumerKey"]!,
consumerSecret: Dribbble["consumerSecret"]!,
authorizeUrl: "https://dribbble.com/oauth/authorize",
accessTokenUrl: "https://dribbble.com/oauth/token",
responseType: "code"
)
oauthswift.authorizeWithCallbackURL( NSURL(string: "dribs://oauth-callback/dribbble")!, scope: "public+write+comment+upload", state: "", success: {
credential, response in
// Get User
var parameters = Dictionary<String, AnyObject>()
oauthswift.client.get("https://api.dribbble.com/v1/user?access_token=\(credential.oauth_token)", parameters: parameters,
success: {
data, response in
let jsonDict: AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
println(jsonDict)
}, failure: {(error:NSError!) -> Void in
println(error)
})
}, failure: {(error:NSError!) -> Void in
println(error.localizedDescription)
})
}
我的登录页面
然后,新的 Safari 页面
在您的 WebViewController.swift
viewDidLoad()
中
myUrl = someurl
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: myUrl)!))