I am looking at how to implement a Facebook invite dialog and noticed that Facebook now offers a new FB App Invite product. Is there a way to use the new App Invite product with Xamarin iOS?
Thanks!
I am looking at how to implement a Facebook invite dialog and noticed that Facebook now offers a new FB App Invite product. Is there a way to use the new App Invite product with Xamarin iOS?
Thanks!
Here is the implemention of app invites
You need to create Native implementaion for appinvites
Just create one interface called IFacebookService
Define Method defination as shown in example
public interface IFacebookservice{
InviteFriends (string appLinkURL, string previewImageURL);
}
and do that implementation on platform side as shown in below
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);
}
}
Usage in Xamarin Forms
var facebookservice=Dependency.Get<IFacebookservice>()
button.click+=delegate{facebookservice.InviteFriends("appurl","previewimageurl")}
It's currently not supported by the Xamarin FB SDK. The invite feature is available from version 4.0, where the transformed version of FB SDK was done on version 3.6.
So you basically have two options:
1) Ask Xamarin dev team to update the FB sdk to version 4.0, you can check it here
2) Since it will probably won't be ready soon, you can take the FB iOS native sdk, and generate a xamarin library by yourself. More details can be found in this link
If you do decide to go on option #2, it would be great if you would share your transformed sdk.
The answer from Jagadeesh is completely correct. Also consider implementing a result handler when returning from the Facebook multi-friend-selector. If at least one friend was invited, the Facebook API feedback will show it. For iOS the result can be 'canceled by the user' or completed
For Android nothing when 'canceled by the user', but if completed:
Android
AppInviteDialog AppInv = new AppInviteDialog(activity);
AppInv.RegisterCallback(callbackManager, invitecallback);
AppInv.Show(content);
var invitecallback = new FacebookCallback<AppInviteDialog.Result>()
{
HandleSuccess = Result =>
{
if ((string)Result.Data == "Bundle[{didComplete=1}]")
{
textbox.Text = "Friend Invited";
}
},
HandleCancel = () =>
{
textbox.Text = "Cancelled";
},
HandleError = Error =>
{
textbox.Text = "Error" + Error.Message;
}
};
iOS
var dlgt = new MyAppInviteDialogDelegate();
var dialog = AppInviteDialog.Show(fromController, content, dlgt);
public class MyAppInviteDialogDelegate : AppInviteDialogDelegate
{
public override void DidComplete(AppInviteDialog appInviteDialog, NSDictionary results)
{
textbox.Text = "Friend Invited";
if (results.Description.Contains("cancel"))
{
textbox.Text = "Cancelled";
}
}
public override void DidFail(AppInviteDialog appInviteDialog, NSError error)
{
textbox.Text = "Error" + error.Description;
}
}