我正在尝试将 Facebook Game Request 文档实现到我的 Swift 项目中,但我:
A) 不确定我是否需要 Unity 来执行此操作,或者我是否可以仅使用我的 IOS 应用程序来执行此操作,并且
B) 如何实现打开 Facebook 游戏请求的正确对话框(文档中的说明似乎已过时)
我看过文档,但还是有点困惑。如果有人可以提供进一步的指导,将不胜感激!
https://developers.facebook.com/docs/games/services/gamerequests#invites
最佳答案
您不需要 Unity,它可以在 Swift 中完成。完全同意文档已过时。
要打开对话框发送请求,您可以使用以下代码(更改消息以及您想要更改的任何内容)
func sendLifeRequest(index: Int) {
let content = FBSDKGameRequestContent()
content.message = "Please help me with 5 lives"
content.data = "5lives"
let id = facebookFriends[index].id as NSString
var to: [NSString] = [NSString]()
to.append(id)
content.recipients = to
FBSDKGameRequestDialog.show(with: content, delegate: self)
}
另外,确保你的 FBSDKGameRequestDialogDelegate 中有这三个函数(它们是必需的)
func gameRequestDialog(_ gameRequestDialog: FBSDKGameRequestDialog!, didCompleteWithResults results: [AnyHashable : Any]!) {
print("request sent")
}
func gameRequestDialog(_ gameRequestDialog: FBSDKGameRequestDialog!, didFailWithError error: Error!) {
print("error sending request")
print(error)
}
func gameRequestDialogDidCancel(_ gameRequestDialog: FBSDKGameRequestDialog!) {
print("request canceled")
}
希望对您有所帮助...
关于ios - Swift 中的 Facebook 游戏请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40187252/