Ejemplo n.º 1
0
        /// <summary>
        /// Shows the native SLComposeViewController to post a message with image and/or URL on Facebook, Twitter, or Weibo.
        /// Raises PostCompleted event when completed.</summary>
        /// <remarks>
        /// This is available in iOS 6.0 and later.
        /// </remarks>
        /// <param name="serviceType"> The service to post to. See <see cref="SLRequest">Constants in SLRequest</see>.</param>
        /// <param name="message"> The message to post or can be null.</param>
        /// <param name="image"> The image to post or can be null.</param>
        /// <param name="url"> The URL to post or can be null.</param>
        /// <param name="checkServiceAvailable"> Whether to check if the service is available first.</param>
        /// <returns> True if it is able to show the native view controller; false if the service type is not available.</returns>
        public static bool Post(string serviceType, string message, UIImage image, String url, bool checkServiceAvailable)
        {
            if (checkServiceAvailable && !SLComposeViewController.IsAvailable(serviceType))
            {
                return(false);
            }

            var vc = SLComposeViewController.ComposeViewController(serviceType);

            if (vc.IsNil)
            {
                return(false);
            }

            vc.completionHandler = _composeViewCompleted;

            if (message != null)
            {
                vc.SetInitialText(message);
            }

            if (image != null)
            {
                vc.AddImage(image);
            }

            if (url != null)
            {
                vc.AddURL(new NSURL(url));
            }

            UIApplication.deviceRootViewController.PresentViewController(vc, true, null);
            return(true);
        }