我正在使用Xamarin.Facebook.Android包。对话框显示正确,请求将传递给正确的收件人,但回调永远不会被调用。我不是100%肯定我应该从哪里获得CallbackManager。
public class FacebookService : IFacebookService
{
public void InviteFriends(FacebookInviteCallbacks facebookInviteCallbacks)
{
if (AppInviteDialog.CanShow())
{
var activity = Xamarin.Forms.Forms.Context as Activity;
var content = new GameRequestContent.Builder().
SetTitle("Check out this game").
SetMessage("Check out this game I play!").
Build() as GameRequestContent;
var dialog = new GameRequestDialog(activity);
dialog.RegisterCallback(CallbackManagerFactory.Create(), new MyFacebookCallback(facebookInviteCallbacks));
dialog.Show(content);
}
}
}
public class MyFacebookCallback : Java.Lang.Object, IFacebookCallback
{
private FacebookInviteCallbacks facebookInviteCallbacks;
public ImcFacebookCallback(FacebookInviteCallbacks facebookInviteCallbacks)
{
this.facebookInviteCallbacks = facebookInviteCallbacks;
}
public void OnCancel()
{
System.Diagnostics.Debug.WriteLine("Cancelled sending invite");
}
public void OnError(FacebookException error)
{
facebookInviteCallbacks.FailedCallback(error.Message);
}
public void OnSuccess(Java.Lang.Object result)
{
System.Diagnostics.Debug.WriteLine(result);
}
}
更新
从我看到的其他示例中可以看出,CallbackManagerFactory.Create()是正确的。
答案 0 :(得分:3)
经过大量的挖掘和反复试验后,我终于开始了这项工作。
在我的FacebookService课程中,我添加了:
public static ICallbackManager callbackManager;
在Invitefriends方法中,在if语句中我改变了这个:
dialog.RegisterCallback(CallbackManagerFactory.Create(), new MyFacebookCallback(facebookInviteCallbacks));
到
callbackManager = CallbackManagerFactory.Create();
dialog.RegisterCallback(callbackManager, new ImcFacebookCallback(facebookInviteCallbacks));
在MainActivity中,我添加了以下覆盖。
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
Services.FacebookService.callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
}
这就是全部。我希望这个方案能够得到更好的记录。