Guest User

Untitled

a guest
Oct 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. public interface IFacebookservice{
  2. InviteFriends (string appLinkURL, string previewImageURL);
  3. }
  4.  
  5. public void InviteFriends (string appLinkURL, string previewImageURL)
  6. {
  7. var fromController = UIApplication.SharedApplication.KeyWindow.RootViewController;
  8. var content = new AppInviteContent {
  9. AppLinkURL = new NSUrl (appLinkURL),
  10. PreviewImageURL = new NSUrl (previewImageURL)
  11. };
  12. AppInviteDialog.Show (fromController, content, null);
  13. }
  14.  
  15. public void InviteFriends(string appLinkURL, string previewImageURL)
  16. {
  17. if (AppInviteDialog.CanShow())
  18. {
  19. var activity = Xamarin.Forms.Forms.Context as Activity;
  20. var content =new AppInviteContent.Builder().SetApplinkUrl(appLinkURL).SetPreviewImageUrl(previewImageURL).Build() as AppInviteContent;
  21. AppInviteDialog.Show(activity, content);
  22. }
  23. }
  24.  
  25. var facebookservice=Dependency.Get<IFacebookservice>()
  26. button.click+=delegate{facebookservice.InviteFriends("appurl","previewimageurl")}
  27.  
  28. AppInviteDialog AppInv = new AppInviteDialog(activity);
  29. AppInv.RegisterCallback(callbackManager, invitecallback);
  30. AppInv.Show(content);
  31. var invitecallback = new FacebookCallback<AppInviteDialog.Result>()
  32. {
  33. HandleSuccess = Result =>
  34. {
  35. if ((string)Result.Data == "Bundle[{didComplete=1}]")
  36. {
  37. textbox.Text = "Friend Invited";
  38. }
  39. },
  40. HandleCancel = () =>
  41. {
  42. textbox.Text = "Cancelled";
  43. },
  44. HandleError = Error =>
  45. {
  46. textbox.Text = "Error" + Error.Message;
  47. }
  48. };
  49.  
  50. var dlgt = new MyAppInviteDialogDelegate();
  51. var dialog = AppInviteDialog.Show(fromController, content, dlgt);
  52. public class MyAppInviteDialogDelegate : AppInviteDialogDelegate
  53. {
  54.  
  55. public override void DidComplete(AppInviteDialog appInviteDialog, NSDictionary results)
  56. {
  57. textbox.Text = "Friend Invited";
  58. if (results.Description.Contains("cancel"))
  59. {
  60. textbox.Text = "Cancelled";
  61. }
  62. }
  63.  
  64. public override void DidFail(AppInviteDialog appInviteDialog, NSError error)
  65. {
  66. textbox.Text = "Error" + error.Description;
  67. }
  68. }
Add Comment
Please, Sign In to add comment