2015-04-07 80 views
0

我使用的是OAuthSwift,它工作的很完美,但是当我点击登录按钮时,它会打开一个新的Safari页面。我想在应用程序中打开URL,但我开始了,我不知道那是怎么回事。Swift:如何在应用程序中打开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

届时,新的Safari网页

It opens the safari new page

+1

使用一个UIWebView – Arbitur

+1

这[SO问题](http://stackoverflow.com/questions/8310109/create -a-uiwebview-and-load-a-website-programmically)解决了你的问题。它是Objective-C,但它可以很容易地转换成Swift –

回答

4

viewDidLoad()WebViewController.swift

myUrl = someurl 
myWebView.loadRequest(NSURLRequest(URL: NSURL(string: myUrl)!)) 
相关问题