我想向我的 Facebook 朋友发送游戏请求。如果接收者尚未安装应用程序,则以下代码会发送邀请请求。
我已经浏览了所有文档(虽然没有很多),但我不确定这里可能出现什么错误。以下是一段代码:
void FacebookInterface::postGameRequest(std::string title, std::string message, std::string pids,
std::string dataJson, int friendType, int inviteType)
{
FBSDKGameRequestDialog *gameReq = [[FBSDKGameRequestDialog alloc] init];
if ([gameReq canShow]) {
gameReq.content =[[FBSDKGameRequestContent alloc] init];
gameReq.content.data = [NSString stringWithUTF8String:dataJson.c_str()];
gameReq.content.message = [NSString stringWithUTF8String:message.c_str()];
gameReq.content.title = [NSString stringWithUTF8String:title.c_str()];
GameRequestDelegate* delegate = [[GameRequestDelegate alloc] init];
int count = 0;
if (!pids.empty()) {
NSArray* receipients = [[NSString stringWithUTF8String:pids.c_str()] componentsSeparatedByString:@","];
gameReq.content.recipients = receipients;
count = (int) [receipients count];
delegate.toList = pids;
delegate.count = count;
} else {
gameReq.content.filters = FBSDKGameRequestFilter::FBSDKGameRequestFilterAppNonUsers;
delegate.count = 0;
}
delegate.friendType = friendType;
delegate.inviteType = inviteType;
gameReq.delegate = delegate;
gameReq.frictionlessRequestsEnabled = YES;
FabricAnswersInterface::getInstance()->logEvent(title, std::to_string(friendType), count);
[gameReq show];
}
}