I want my custom login button to have blue color when:
I want my custom login button to have gray color when:
Well, I tried doing it with if/else condition as you can see but in order to really test this I did the following:
Now, I am certain that my custom login button will have GrayColor because by removing an authorized app from my Facebook settings I have also deleted an accesstoken however, that's not the case.
I need my custom button to appear active(blue color) and inactive(gray color) depending on whether or not user has authorized an app
Thanks in advance
My code:
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()
}
}
}
}
Why must you delete your application on Facebook?
When you run the simulator you can choose from the top bar from the mac: Simulator > Reset Content Settings... > Then Click Reset
This should erase all memory from the simulator. Then you can test what happens when a Facebook session and access token doesn't exist.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.