简体   繁体   中英

AccessToken still exists even after removing an app from Facebook settings

I want my custom login button to have blue color when:

  1. The user has authorized the app and an accesstoken still exists

I want my custom login button to have gray color when:

  1. An access token has expired and I want the user to log in and get a new one

Well, I tried doing it with if/else condition as you can see but in order to really test this I did the following:

  1. Went to my Facebook settings (WEB)
  2. Clicked on 'Apps'
  3. Searched for the app and removed it

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM