Example #1
0
        /// <summary>
        /// Shows the image picker.
        /// </summary>
        public static void ShowImagePicker(UIImagePickerControllerSourceType source         = UIImagePickerControllerSourceType.PhotoLibrary,
                                           UIImagePickerControllerCameraDevice cameraDevice = UIImagePickerControllerCameraDevice.Rear)
        {
            _picker = new UIImagePickerController();
//			_picker.AllowsEditing = true;
            _picker.sourceType = source;
//			_picker.Delegate = ImagePickerControllerDelegate.instance;
            _picker.DidFinishPickingMediaWithInfo += _OnPickedMedia;
            _picker.DidCancel += _OnCancelledPick;
            if (source == UIImagePickerControllerSourceType.Camera)
            {
                _picker.cameraDevice = cameraDevice;
            }

            var rootVc = UIApplication.deviceRootViewController;

            if (CoreXT.IsiPad && (source != UIImagePickerControllerSourceType.Camera))
            {
                if (_popover == null)
                {
                    _popover                      = new UIPopoverController(_picker);
                    _popover.DidDismiss          += _OnCancelledPick;
                    _popover.shouldDismissHandler = _ShouldDismissPopover;
                }
                else
                {
                    _popover.contentViewController = _picker;
                }

                var rect = rootVc.view.bounds;
                rect.x      = rect.width / 2;
                rect.y      = rect.height;
                rect.width  = 1;
                rect.height = 1;
                _popover.PresentPopover(
                    rect,
                    rootVc.view,
                    UIPopoverArrowDirection.Down,
                    true);
            }
            else
            {
                rootVc.PresentViewController(_picker, true, null);
            }
        }
Example #2
0
        /// <summary>
        /// Shows the native UIActivityViewController to share message, images, and URLs
        /// via Facebook, Twitter, Weibo, email, SMS, print, copy, save to camera roll, or
        /// assign to contact.
        /// Raises ShareCompleted event when completed.
        /// </summary>
        /// <remarks>
        /// This is available in iOS 6.0 and later.</remarks>
        ///
        /// <param name="items"> An array of items to share. Each item can be a string, NSURL, Texture2D, or UIImage.
        ///             Strings starting with http:// or https:// will be automatically converted to URLs.</param>
        /// <param name="excludedActivityTypes"> An array of strings representing the activity types to exclude from sharing.
        ///             See <see cref="UIActivity">Constants in UIActivity</see>.</param>
        public static void Share(object[] items, string[] excludedActivityTypes = null)
        {
            var nativeItems = new object[items.Length];

            for (int i = 0; i < items.Length; i++)
            {
                var item = items[i];
                if (item is string)
                {
                    string str = item as string;
                    if (str.StartsWith("http://") || str.StartsWith("https://"))
                    {
                        nativeItems[i] = new NSURL(str);
                    }
                    else
                    {
                        nativeItems[i] = str;
                    }
                }
                else if (item is Texture2D)
                {
                    nativeItems[i] = UIImage.FromTexture2D(item as Texture2D);
                }
                else if (item is UIImage)
                {
                    nativeItems[i] = item;
                }
                else if (item is NSURL)
                {
                    nativeItems[i] = item;
                }
                else
                {
                    throw new U3DXTException("Unexpected item type: " + item.GetType());
                }
            }

            var vc = new UIActivityViewController(nativeItems, null);

            if (vc.IsNil)
            {
                return;
            }

            vc.completionHandler = _activityViewCompleted;
            if (excludedActivityTypes != null)
            {
                vc.excludedActivityTypes = excludedActivityTypes;
            }

            var rootVc = UIApplication.deviceRootViewController;

            if (CoreXT.IsiPad)
            {
                if (_popover == null)
                {
                    _popover = new UIPopoverController(vc);
                }
                else
                {
                    _popover.contentViewController = vc;
                }

                var rect = rootVc.view.bounds;
                rect.x      = rect.width / 2;
                rect.y      = rect.height;
                rect.width  = 1;
                rect.height = 1;
                _popover.PresentPopover(
                    rect,
                    rootVc.view,
                    UIPopoverArrowDirection.Down,
                    true);
            }
            else
            {
                rootVc.PresentViewController(vc, true, null);
            }
        }