Cocos2dx接入ios平台Facebook SDK,思路大家可以参考下,这里只是接入了登录功能,并且可以下载icon头像,另外,大家注意下,邀请功能Facebook已经关闭。
Facebook SDK ios地址 (科学上网)
https://developers.facebook.com/docs/ios/getting-started/
1:通过pod方式导入facebook sdk。
2:首先修改info.plist
3:登录代码oc版本
-(void)FBLogin
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions: @[@"public_profile"]
fromViewController: _viewController
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error)
{
FaceBookManager::GetInstance()->FBLoginCallBack("2");
}
else if (result.isCancelled)
{
NSLog(@"------------------------------Cancelled");
FaceBookManager::GetInstance()->FBLoginCallBack("1");
}
else
{
NSLog(@"------------------------------Logged in success");
NSString* NStoken = result.token.tokenString; NSDictionary*params=[NSDictionary new];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:result.token.userID
parameters:params
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
NSString* NSid = [result objectForKey:@"id"];
std::string sId = std::string([NSid UTF8String]);
NSString* NSname = [result objectForKey:@"name"];
std::string name = std::string([NSname UTF8String]);
std::string gender = "default";
std::string locale = "default";
std::string token = std::string([NStoken UTF8String]);
std::string packageName = std::string("Anime_Piano_iOS");
std::string ParamSeparator = std::string(";");
std::string userInfo = sId + ParamSeparator + name + ParamSeparator + gender + ParamSeparator +
locale + ParamSeparator + token + ParamSeparator + packageName;
std::string icon_url = "https://graph.facebook.com/" + sId + "/picture?type=large";
}];
}
}];
}
如有错误,大家可以一起交流
联系方式 qq: 940299880