[英]AccessToken still exists even after removing an app from Facebook settings
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: 好吧,正如您所见,我尝试使用if / else条件进行此操作,但是为了真正进行测试,我执行了以下操作:
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.