简体   繁体   English

即使从Facebook设置中删除了应用程序,AccessToken仍然存在

[英]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: 好吧,正如您所见,我尝试使用if / else条件进行此操作,但是为了真正进行测试,我执行了以下操作:

  1. Went to my Facebook settings (WEB) 转到我的Facebook设置(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. 现在,我确定我的自定义登录按钮将具有GrayColor,因为通过从我的Facebook设置中删除授权的应用程序,我还删除了访问令牌,但事实并非如此。

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? 为什么必须在Facebook上删除您的应用程序?

When you run the simulator you can choose from the top bar from the mac: Simulator > Reset Content Settings... > Then Click Reset 运行模拟器时,可以从Mac的顶部栏中选择:模拟器>重置内容设置...>然后单击重置

This should erase all memory from the simulator. 这将清除模拟器中的所有内存。 Then you can test what happens when a Facebook session and access token doesn't exist. 然后,您可以测试当Facebook会话和访问令牌不存在时会发生什么。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift:即使从Facebook设置中删除了应用程序,也始终返回Facebook访问令牌 - Swift: Facebook Access Token is always returned even after removing App from Facebook settings 即使从Facebook应用程序设置中删除了应用程序,用户仍然可以访问应用程序 - User able to access app even after removing app from Facebook App Settings 杀毒App(iOS)后Facebook AccessToken无 - Facebook AccessToken nil after killing App (iOS) Facebook SDK:即使登录后,AccessToken.CurrentAccessToken始终为null - Facebook SDK: AccessToken.CurrentAccessToken always null, even after logging in 为什么即使我越狱后,iOS 6.1.1中的SandBox仍然存在? - Why SandBox in iOS 6.1.1 still exists for App even after I have jailbreak? 从Apple AppStore删除应用程序后,仍然可以恢复应用程序内购买吗? - After removing application from Apple AppStore, will restoring of in-app purchases still work? 如何从Facebook SDK获取accessToken - How to get the accessToken from Facebook SDK 即使从供应配置文件中删除了UDID,iOS应用仍在安装到设备中 - iOS app is still installing into device even after UDID removed from the provisioning profile 重启iOS应用后检查相机胶卷中照片是否仍然存在 - Check if photo still exists in camera roll after restart ios app 永久数据仍然导致应用程序崩溃,即使在应用程序更新后 - Persistent data still causing application to crash even after app update
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM