[英]Why does FBSDKAccessToken.currentAccessToken() returns nil on my device but works fine in the iOS simulator?
In my IOS9 application I use the Facebook SDK 4.7.0 graph api to search for public places. 在我的IOS9应用程序中,我使用Facebook SDK 4.7.0图形api搜索公共场所。
I use the FBSDKApplicationDelegate in my apps delegate which I believe provides me with valid app access token (since I don't use any user specific data an application login is sufficient for me). 我在我的应用程序委托中使用FBSDKApplicationDelegate,我相信它为我提供了有效的应用程序访问令牌(因为我不使用任何用户特定数据,因此应用程序登录足以满足我的需要)。
When I call FBSDKAccessToken.currentAccessToken() in my ViewController to check if the token is valid I always succeed in the simulator but not when deployed on the real device. 当我在ViewController中调用FBSDKAccessToken.currentAccessToken()来检查令牌是否有效时,我总是会在模拟器中成功,但是在实际设备上部署时却不会成功。
Any suggestions? 有什么建议么?
I have followed the new ios9 guide and provided the additional info in my plist. 我遵循了新的ios9指南,并在我的plist中提供了其他信息。 Since my application is still in development my Facebook companion app (which holds my app id and secret) are still not available for general public. 由于我的应用程序仍在开发中,因此我的Facebook伴侣应用程序(包含我的应用程序ID和机密信息)仍然无法向公众开放。 Could this be a problem? 这可能是个问题吗?
for checking facebook permission..& give a permission...if permission exist then automatically get accesstoken other wise ask for login... 用于检查facebook权限..&授予权限...如果存在权限,则自动获得accesstoken其他明智的登录要求...
For Swift 对于斯威夫特
var login: FBSDKLoginManager = FBSDKLoginManager()
login.logInWithReadPermissions(["public_profile", "email"], handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
if (error != nil)
{
//Process error
}
else if result.isCancelled
{
//Handle cancellations
}
else
{
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("email"){
//Do work
}
}
})
For Objective c: 对于目标c:
check Permission like this. 检查这样的权限。 following code use .. 以下代码使用..
if ([[FBSDKAccessToken currentAccessToken]hasGranted:@"email"])
{
// add your coding here after login call this block automatically.
}
else
{
//login code **//if accesstoken expired...then call this block**
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:@[@"public_profile", @"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.