Exemplo n.º 1
0
        private static async Task ShareImageAsync(ImageSource image, string message)
        {
            ShareDialog       dialog  = new ShareDialog();
            SharePhotoContent content = new SharePhotoContent();

            var handler = image.GetHandler();

            if (handler == null)
            {
                return;
            }

            var uiImage = await handler.LoadImageAsync(image);

            var items = new List <NSObject> {
                new NSString(message ?? string.Empty)
            };

            items.Add(uiImage);

            var controller = new UIActivityViewController(items.ToArray(), null);

            SharePhoto photo = SharePhoto.From(uiImage, false);

            SharePhoto[] lshare = new SharePhoto[1];
            lshare[0]      = photo;
            content.Photos = lshare;

            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            dialog.Mode = ShareDialogMode.Automatic;
            System.Diagnostics.Debug.WriteLine(dialog.Mode.ToString());
            dialog.SetShareContent(content);
            dialog.Show();
        }
        public void ShareLinkOnFacebook(string text, string description, string link)
        {
            ShareLinkContent link1 = new ShareLinkContent();

            link1.SetContentUrl(new NSUrl(link));
            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link1);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(link1, shareDelegate);
            }
        }
        public void ShareImageOnFacebook(string caption, string imagePath)
        {
            SharePhoto tt = SharePhoto.From(new UIImage(imagePath), true);

            tt.Caption = caption;
            SharePhotoContent content = new SharePhotoContent();

            content.Photos = new SharePhoto[] { tt };
            content.SetContentUrl(new NSUrl(imagePath));

            var shareDelegate = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.FeedBrowser;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(content);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Mode = ShareDialogMode.Native;
                dialog.Show();
            }
            else
            {
                ShareAPI.Share(content, shareDelegate);
            }
        }
Exemplo n.º 4
0
 public static void ShareVideoOnFacebook(string videoUrl, byte[] previewImage = null, string hashtag = null)
 {
     Thread.UI.Post(() =>
     {
         var video = new ShareVideo(new NSCoder())
         {
             PreviewPhoto = SharePhoto.From(UIImage.LoadFromData(NSData.FromArray(previewImage)), true),
             VideoUrl     = NSUrl.FromString(videoUrl)
         };
         var content = new ShareVideoContent {
             Video = video
         };
         if (string.IsNullOrEmpty(hashtag))
         {
             content.Hashtag = new Hashtag()
             {
                 StringRepresentation = hashtag
             }
         }
         ;
         var dialog = new ShareDialog
         {
             Mode = ShareDialogMode.ShareSheet,
             FromViewController = (UIViewController)UIRuntime.NativeRootScreen
         };
         dialog.SetShareContent(content);
         dialog.Show();
     });
 }
Exemplo n.º 5
0
 public static void SharePhotosOnFacebook(IEnumerable <byte[]> photos, string hashtag = null)
 {
     Thread.UI.Post(() =>
     {
         var content      = new SharePhotoContent();
         var sharedPhotos = new List <SharePhoto>();
         foreach (var photo in photos)
         {
             sharedPhotos.Add(SharePhoto.From(UIImage.LoadFromData(NSData.FromArray(photo)), true));
         }
         content.Photos = sharedPhotos.ToArray();
         if (!string.IsNullOrEmpty(hashtag))
         {
             content.Hashtag = new Hashtag()
             {
                 StringRepresentation = hashtag
             }
         }
         ;
         var dialog = new ShareDialog
         {
             Mode = ShareDialogMode.ShareSheet,
             FromViewController = (UIViewController)UIRuntime.NativeRootScreen
         };
         dialog.SetShareContent(content);
         dialog.Show();
     });
 }
Exemplo n.º 6
0
        public static async Task ShareFacebook(UIViewController controller, Post post)
        {
            var dialog = new ShareDialog();

            dialog.FromViewController = controller;
            dialog.Mode = ShareDialogMode.Automatic;

            if (post.Links.Any())
            {
                var content = new ShareLinkContent();

                content.SetContentUrl(new NSUrl(post.Links.FirstOrDefault().LinkUrl));
                dialog.SetShareContent(content);
            }
            if (post.Images.Any())
            {
                var content = new SharePhotoContent();
                var path    = await DownloadFileIfNecessary(post.Images.FirstOrDefault().Url);

                content.Photos = new SharePhoto[1] {
                    SharePhoto.From(UIImage.FromFile(path), true)
                };
                dialog.SetShareContent(content);
            }

            if (post.Videos.Any())
            {
                var path = await DownloadFileIfNecessary(post.Videos.FirstOrDefault().Url);

                ALAssetsLibrary library = new ALAssetsLibrary();
                library.WriteVideoToSavedPhotosAlbum(NSUrl.FromFilename(path), (arg1, arg2) =>
                {
                    controller.InvokeOnMainThread(() =>
                    {
                        var content   = new ShareVideoContent();
                        content.Video = ShareVideo.From(arg1.AbsoluteUrl);
                        dialog.SetShareContent(content);
                        dialog.Show();
                    });
                });
            }
            NSError error = new NSError();

            dialog.ValidateWithError(out error);

            var result = dialog.Show();
        }
Exemplo n.º 7
0
 public static void ShareLinkOnFacebook(string quote, string url)
 {
     Thread.UI.Post(() =>
     {
         var content = new ShareLinkContent();
         content.SetContentUrl(NSUrl.FromString(url));
         content.Quote = quote;
         var dialog    = new ShareDialog
         {
             Mode = ShareDialogMode.ShareSheet,
             FromViewController = (UIViewController)UIRuntime.NativeRootScreen
         };
         dialog.SetShareContent(content);
         dialog.Show();
     });
 }
        private OperationResult ShowSharingSheet(ISharingContent content)
        {
            var dialog = new ShareDialog();

            dialog.FromViewController = NavigationHelper.GetActiveViewController();
            dialog.SetShareContent(content);
            dialog.Mode = ShareDialogMode.ShareSheet;
            bool success = dialog.Show();

            if (success)
            {
                return(OperationResult.AsSuccess());
            }
            else
            {
                return(OperationResult.AsFailure("Could not display Facebook sharing sheet"));
            }
        }
        public void ShareTextOnFacebook(string text)
        {
            ShareLinkContent link = new ShareLinkContent();
            var shareDelegate     = new FbDelegate();

            var dialog = new ShareDialog();

            dialog.Mode = ShareDialogMode.Native;
            dialog.SetDelegate(shareDelegate);
            dialog.SetShareContent(link);
            dialog.FromViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
            bool isInstalled = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(urlString: "fb://"));

            if (isInstalled)
            {
                dialog.Show();
            }
            else
            {
                new UIAlertView("Error", "Cannot share text when app is not installed", null, "Ok", null).Show();
            }
        }
Exemplo n.º 10
0
        public async void SendOpenGraph(object source, ChallengeModel model, string message = null)
        {
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;

            await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            NSUrl url = new NSUrl(shareTemplate?.PostHref ?? model.ShareImage);

            if (string.IsNullOrEmpty(url?.AbsoluteString))
            {
                new UIAlertView("Sharing Error", string.IsNullOrEmpty(shareResponse?.ResponseMessage) ? "Sorry. No url come from server" : shareResponse.ResponseMessage, source as IUIAlertViewDelegate, "Ok").Show();
                return;
            }

            ShareDialog dialog = new ShareDialog();

            dialog.SetShouldFailOnDataError(true);
            dialog.FromViewController = source as UIViewController;
            dialog.SetDelegate(source as ISharingDelegate ?? new FBSharingDelegate());

            NSString[] keys;
            NSObject[] objects;

            string imgUrl = null;

            try
            {
                if (!string.IsNullOrEmpty(model.ShareImage))
                {
                    await ImageService.Instance.LoadUrl(model.ShareImage).IntoAsync(new UIImageView());

                    imgUrl = model.ShareImage;
                }
            }
            catch (Exception) { }

            if (string.IsNullOrEmpty(imgUrl))
            {
                keys = new NSString[] {
                    new NSString("og:type"),
                    new NSString("og:url"),
                    new NSString("og:title"),
                    new NSString("og:description"),
                };
                objects = new NSObject[] {
                    NSObject.FromObject("article"),
                    NSObject.FromObject(url),
                    NSObject.FromObject(string.IsNullOrEmpty(shareTemplate?.PostTitle) ? url.AbsoluteString : shareTemplate.PostTitle),
                    NSObject.FromObject(string.IsNullOrEmpty(message) ? shareTemplate?.PostDescription ?? " " : message),
                };
            }
            else
            {
                keys = new NSString[] {
                    new NSString("og:type"),
                    new NSString("og:url"),
                    new NSString("og:title"),
                    new NSString("og:description"),
                    new NSString("og:image"),
                };
                objects = new NSObject[]
                {
                    NSObject.FromObject("article"),
                    NSObject.FromObject(url),
                    NSObject.FromObject(string.IsNullOrEmpty(shareTemplate?.PostTitle) ? url.AbsoluteString : shareTemplate.PostTitle),
                    NSObject.FromObject(string.IsNullOrEmpty(message) ? shareTemplate?.PostDescription ?? " " : message),
                    NSObject.FromObject(imgUrl),
                };
            }

            var propesties       = new NSDictionary <NSString, NSObject>(keys, objects);
            var openGraph        = ShareOpenGraphObject.ObjectWithProperties(propesties);
            var action           = ShareOpenGraphAction.Action("news.publishes", openGraph, "article");
            var contentOpenGraph = new ShareOpenGraphContent
            {
                Action = action,
                PreviewPropertyName = "article"
            };

            dialog.SetShareContent(contentOpenGraph);
            dialog.Mode = ShareDialogMode.Web;

            dialog.Show();

            if (dialog.Mode == ShareDialogMode.Web)
            {
                StylishFbWebDialog();
            }
        }
Exemplo n.º 11
0
        public async void ShareFacebookChallenge(object source, ChallengeModel model, string message = null)
        {
            ShareTemplateModel shareTemplate = null;
            ShareResponseModel shareResponse = null;
            await SL.Manager.RefreshShareTemplate(model.ShareTemplateURL, (response) =>
            {
                shareTemplate = response?.ShareTemplate;
                shareResponse = response;
            });

            NSUrl url = new NSUrl(shareTemplate?.PostHref ?? model.ShareImage);

            ShareDialog dialog = new ShareDialog();

            dialog.SetShouldFailOnDataError(true);
            dialog.FromViewController = source as UIViewController;
            dialog.SetDelegate(source as ISharingDelegate ?? new FBSharingDelegate());

            if (string.IsNullOrEmpty(message) && model.FBShareType == "image")
            {
                UIImageView imageView = new UIImageView();
                try
                {
                    await ImageService.Instance.LoadUrl(model.ShareImage).IntoAsync(imageView);
                }
                catch (Exception)
                {
                    try
                    {
                        await ImageService.Instance.LoadUrl(model.Image).IntoAsync(imageView);
                    }
                    catch (Exception)
                    {
                    }
                }

                dialog.SetShareContent(new SharePhotoContent()
                {
                    Photos = new SharePhoto[] { SharePhoto.From(imageView.Image, true) }
                });
                dialog.Mode = ShareDialogMode.Native;
            }
            else if (string.IsNullOrEmpty(message) && (model.FBShareType == "link" || model.FBShareType == null))
            {
                ShareLinkContent contentLink = new ShareLinkContent();
                if (string.IsNullOrEmpty(url?.AbsoluteString))
                {
                    new UIAlertView("Sharing Error", string.IsNullOrEmpty(shareResponse?.ResponseMessage) ? "Sorry. No url come from server" : shareResponse.ResponseMessage, source as IUIAlertViewDelegate, "Ok").Show();
                    return;
                }
                contentLink.SetContentUrl(url);

                dialog.SetShareContent(contentLink);
                dialog.Mode = ShareDialogMode.Web;
            }
            else
            {
                SendOpenGraph(source, model, message);
                return;
            }

            if (!dialog.CanShow())
            {
                SendOpenGraph(source, model, message);
                return;
            }
            dialog.Show();

            if (dialog.Mode == ShareDialogMode.Web)
            {
                StylishFbWebDialog();
            }
        }