我正在研究如何实现Facebook邀请对话框,并注意到Facebook现在提供了一个新的FB App Invite产品。
有没有办法在Xamarin iOS上使用新的App Invite产品?
谢谢!
最佳答案
这是应用程序邀请的实现
您需要为Appinvites创建本机实现
只需创建一个名为IFacebookService的接口
定义方法定义,如示例所示
public interface IFacebookservice{
InviteFriends (string appLinkURL, string previewImageURL);
}
并在平台端进行该实现,如下所示
iOS
FacebookService.CS
public void InviteFriends (string appLinkURL, string previewImageURL)
{
var fromController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var content = new AppInviteContent {
AppLinkURL = new NSUrl (appLinkURL),
PreviewImageURL = new NSUrl (previewImageURL)
};
AppInviteDialog.Show (fromController, content, null);
}
Android
FacebookService.Cs
public void InviteFriends(string appLinkURL, string previewImageURL)
{
if (AppInviteDialog.CanShow())
{
var activity = Xamarin.Forms.Forms.Context as Activity;
var content =new AppInviteContent.Builder().SetApplinkUrl(appLinkURL).SetPreviewImageUrl(previewImageURL).Build() as AppInviteContent;
AppInviteDialog.Show(activity, content);
}
}
Xamarin形式的用法
var facebookservice=Dependency.Get<IFacebookservice>()
button.click+=delegate{facebookservice.InviteFriends("appurl","previewimageurl")}