0
我想我的自定義登錄按鈕有藍色時:的accessToken甚至消除來自Facebook的應用程序後,仍然存在設置
- 該用戶已授權應用程序和的accessToken仍然存在
我希望我的自定義登錄按鈕有灰色時:
- 訪問令牌已經過期,我希望用戶登錄並獲得一個新的
好吧,我試着用的if/else條件,你可以看到,但要真正檢驗這個做我做了以下內容:
- 去了我的Facebook設置(WEB)
- 被點擊在「應用」搜索的應用
- ,並刪除它現在
,我敢肯定,我的自定義登錄按鈕,將有GrayColor,因爲從我的Facebook設置我甲肝刪除授權的應用程序e也刪除了一個accesstoken,但事實並非如此。
我取決於是否用戶已授權的應用程序提前
由於需要我的自定義按鈕,出現積極的(藍色)和非活動(灰色)
我的代碼:
import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
class ViewController: UIViewController {
let loginButton: UIButton = UIButton(type: .Custom)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if FBSDKAccessToken.currentAccessToken() != nil {
loginButton.backgroundColor = UIColor.blueColor()
} else {
loginButton.backgroundColor = UIColor.grayColor()
}
loginButton.frame = CGRectMake(0, 0, 180, 40)
loginButton.setTitle("My Login Button", forState: .Normal)
// Handle clicks on the button
loginButton.addTarget(self, action: "loginWithFacebook", forControlEvents: .TouchUpInside)
// Add the button to the view
self.view!.addSubview(loginButton)
}
func loginWithFacebook() {
let login: FBSDKLoginManager = FBSDKLoginManager()
login.logInWithPublishPermissions(["publish_actions"], fromViewController: self) { (result: FBSDKLoginManagerLoginResult!, error) -> Void in
if (error != nil) {
NSLog("Process error")
}
else if result.isCancelled {
NSLog("Cancelled")
}
else {
NSLog("Logged in")
self.loginButton.backgroundColor = UIColor.blueColor()
}
}
}
}
這正是我想要的。非常感謝 –