Swift:如何在应用程序中打开URL

时间:2015-04-07 08:05:45

标签: ios swift safari mobile-safari 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)
    })
}

我的登录页面

My Login Page

然后,新的狩猎页面

It opens the safari new page

1 个答案:

答案 0 :(得分:4)

viewDidLoad()

WebViewController.swift
myUrl = someurl
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: myUrl)!))