我设法使用自定义类将 Facebook (Xamarin.Facebook.iOS) 集成到我的游戏中(ShareDialog 具有受保护的构造函数):
public class MyShareDialog : Facebook.ShareKit.ShareDialog
{
public MyShareDialog() : base(NSObjectFlag.Empty)
{
}
}
然后我创建并显示对话框:
string url = "http://my-url.com/class-to-generate-picture.php?score=" + Board.Score + "&textUp=" +
System.Web.HttpUtility.UrlEncode("facebook_I_Scored".Localize());
var myShareDialog = new MyShareDialog();
var content = new Facebook.ShareKit.ShareLinkContent {
ContentDescription = "facebook_URLTitle".Localize(),
ContentTitle = "facebook_URLDescription1".Localize() + " " +
Board.Score + " " + "facebook_URLDescription2".Localize(),
ImageURL = new NSUrl(url)};
content.SetContentUrl(new NSUrl("http://my-url.com"));
myShareDialog.SetShareContent(content);
myShareDialog.SetDelegate(new MyShareDelegate());
myShareDialog.Show();
Localize() 是我获取本地化字符串的扩展方法(我将此代码用于 Windows 和 Android,此扩展使我对共享代码感到舒适:))。Board.Score 是一个静态整数,其中包含 - 是的 - 分数。
MyShareDelegate:
public class MyShareDelegate : Facebook.ShareKit.ISharingDelegate
{
public IntPtr Handle { get; }
public void DidComplete (Facebook.ShareKit.ISharing sharer, NSDictionary results)
{
}
public void DidFail (Facebook.ShareKit.ISharing sharer, NSError error)
{
}
public void DidCancel (Facebook.ShareKit.ISharing sharer)
{
}
public void Dispose()
{
}
}
我有两个问题:
未调用 DidComplete/DidFail/DidCancel。
一切正常,共享正在时间轴上发布,但单击共享/取消后,对话框没有关闭......
我究竟做错了什么?