Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IFacebookservice{
- InviteFriends (string appLinkURL, string previewImageURL);
- }
- 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);
- }
- 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);
- }
- }
- var facebookservice=Dependency.Get<IFacebookservice>()
- button.click+=delegate{facebookservice.InviteFriends("appurl","previewimageurl")}
- 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;
- }
- };
- 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;
- }
- }
Add Comment
Please, Sign In to add comment