[英]Objective-C : “receiver FBSDKAccessToken for class message is a forward declaration”
It is showing this error to me . 它向我显示了此错误。 All I did was download the Facebook SDK with CocoaPods and i'm trying to log in , but can not because of this mistake =(
我所做的就是下载带有CocoaPods的Facebook SDK,但我正尝试登录,但不能因为这个错误=(
FBSDKAccessToken and FBSDKGraphRequest are with this same error... FBSDKAccessToken和FBSDKGraphRequest与此错误相同...
This is my code: 这是我的代码:
#import "TestesViewController.h"
#import "FBSDKCoreKit.h"
#import "FBSDKLoginKit.h"
@implementation TestesViewController
-(void) viewDidLoad {
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc]init];
loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
loginButton.center = self.view.center;
[self.view addSubview:loginButton];
}
- (IBAction)loadButton:(id)sender {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
}
}
@end
Does changing 是否改变
#import "FBSDKLoginKit.h"
#import "FBSDKCoreKit.h"
to 至
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
fix the issue? 解决问题? If not, there is likely a problem with the header search paths in your project/workspace.
如果不是这样,则您的项目/工作区中的标题搜索路径可能存在问题。
Here you are using custom loadButton instead of FBSDKLogin button, so I think in order to use your custom FB login button your parameters cannot be nil, you need to provide parameter. 在这里,您使用的是自定义loadButton而不是FBSDKLogin按钮,因此,我认为为了使用自定义FB登录按钮,您的参数不能为nil,需要提供参数。 Moreover, you need to first login user using login manager in order to get access token which would be nil if user had never logged in.Once you get access token you need to store it somewhere, probably in user defaults, so I am removing that part for now.Try changing the code to:
此外,您需要先使用登录管理器登录用户才能获得访问令牌,如果用户从未登录过,访问令牌将为零。一旦获得访问令牌,则需要将其存储在某个位置(可能是用户默认设置),因此我将其删除现在尝试将代码更改为:
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithReadPermissions:@[@"email",@"user_birthday",@"public_profile"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
// if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields":@"first_name, last_name, picture.type(large),email"}]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
}
}];
//}
}];
insert this code to your load button part. 将此代码插入您的加载按钮部分。 This is working for me.
这对我有用。 This might work for you.
这可能对您有用。 If you really want to make a custom FB login button, consider Custom FB button
如果您确实要创建自定义FB登录按钮,请考虑“ 自定义FB”按钮
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.