private void Picker_DidPickDocuments(UIDocumentPickerViewController controller, NSUrl[] urls)
 {
     foreach (var url in urls)
     {
         this.Picker_DidPickDocument(controller, url);
     }
 }
        public void DidPickDocumentPicker(UIDocumentMenuViewController documentMenu, UIDocumentPickerViewController documentPicker)
        {
            documentPicker.DidPickDocument += DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled    += DocumentPicker_WasCancelled;

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(documentPicker, true, null);
        }
Exemple #3
0
        async Task <IEnumerable <FileResult> > PlatformPickAsync(PickOptions options, bool allowMultiple = false)
        {
            var allowedUtis = options?.FileTypes?.Value?.ToArray() ?? new string[]
            {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            var tcs = new TaskCompletionSource <IEnumerable <FileResult> >();

            // Use Open instead of Import so that we can attempt to use the original file.
            // If the file is from an external provider, then it will be downloaded.
            using var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Open);
            if (OperatingSystem.IsIOSVersionAtLeast(11, 0))
            {
                documentPicker.AllowsMultipleSelection = allowMultiple;
            }
            documentPicker.Delegate = new PickerDelegate
            {
                PickHandler = urls => GetFileResults(urls, tcs)
            };

            if (documentPicker.PresentationController != null)
            {
                documentPicker.PresentationController.Delegate =
                    new UIPresentationControllerDelegate(() => GetFileResults(null, tcs));
            }

            var parentController = WindowStateManager.Default.GetCurrentUIViewController(true);

            parentController.PresentViewController(documentPicker, true, null);

            return(await tcs.Task);
        }
 /// <summary>
 /// Callback method called by document picker when file has been picked; this is called
 /// up to iOS 10.
 /// </summary>
 /// <param name="sender">sender object (document picker)</param>
 /// <param name="args">event args</param>
 private static void Pvc_DidPickDocument(object sender, UIDocumentPickedEventArgs args)
 {
     try
     {
         /*
          * var securityEnabled = args.Url.StartAccessingSecurityScopedResource();
          * var doc = new UIDocument(args.Url);
          *
          * string filename = doc.LocalizedName;
          * string pathname = doc.FileUrl?.Path;
          *
          * args.Url.StopAccessingSecurityScopedResource();
          * if (!string.IsNullOrWhiteSpace(pathname))
          * {
          *  // iCloud drive can return null for LocalizedName.
          *  if (filename == null && pathname != null)
          *      filename = System.IO.Path.GetFileName(pathname);
          *
          *  tcs.TrySetResult(new StorageFile(pathname));
          * }
          * else
          *  tcs.TrySetResult(null);
          */
         tcs.TrySetResult(new StorageFile(args.Url));
     }
     catch (Exception ex)
     {
         tcs.SetException(ex);
     }
     tcs = null;
     pvc.Dispose();
     pvc = null;
 }
        partial void OpenPicker_TouchUpInside(UIButton sender)
        {
            var docPicker = new UIDocumentPickerViewController(_docTypes, UIDocumentPickerMode.Import);

            docPicker.DidPickDocument += DocPicker_DidPickDocument;
            PresentViewController(docPicker, true, null);
        }
        private void Picker_DidPickDocument(UIDocumentPickerViewController controller, NSUrl url)
        {
            bool       securityEnabled = url.StartAccessingSecurityScopedResource();
            UIDocument doc             = new UIDocument(url);
            NSData     data            = NSData.FromUrl(url);

            byte[] dataBytes = new byte[data.Length];

            System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

            string filename = doc.LocalizedName;
            string pathname = doc.FileUrl?.ToString();

            // iCloud drive can return null for LocalizedName.
            if (filename == null)
            {
                // Retrieve actual filename by taking the last entry after / in FileURL.
                // e.g. /path/to/file.ext -> file.ext

                // filesplit is either:
                // 0 (pathname is null, or last / is at position 0)
                // -1 (no / in pathname)
                // positive int (last occurence of / in string)
                int filesplit = pathname?.LastIndexOf('/') ?? 0;

                filename = pathname?.Substring(filesplit + 1);
            }

            this.OnFilePicked(new FilePickerEventArgs(dataBytes, filename, pathname));
        }
        private async Task <StorageFolder?> PickSingleFolderTaskAsync(CancellationToken token)
        {
            var rootController = UIApplication.SharedApplication?.KeyWindow?.RootViewController;

            if (rootController == null)
            {
                throw new InvalidOperationException("Root controller not initialized yet. FolderPicker invoked too early.");
            }

            var documentTypes = new string[] { UTType.Folder };

            using var documentPicker = new UIDocumentPickerViewController(documentTypes, UIDocumentPickerMode.Open);

            var completionSource = new TaskCompletionSource <NSUrl?>();

            documentPicker.OverrideUserInterfaceStyle = CoreApplication.RequestedTheme == SystemTheme.Light ?
                                                        UIUserInterfaceStyle.Light : UIUserInterfaceStyle.Dark;

            documentPicker.Delegate = new FolderPickerDelegate(completionSource);
            documentPicker.PresentationController.Delegate = new FolderPickerPresentationControllerDelegate(completionSource);

            await rootController.PresentViewControllerAsync(documentPicker, true);

            var nsUrl = await completionSource.Task;

            if (nsUrl == null)
            {
                return(null);
            }

            return(StorageFolder.GetFromSecurityScopedUrl(nsUrl, null));
        }
    public async Task <IReadOnlyList <IStorageFile> > OpenFilePickerAsync(FilePickerOpenOptions options)
    {
        UIDocumentPickerViewController documentPicker;

        if (OperatingSystem.IsIOSVersionAtLeast(14))
        {
            var allowedUtis = options.FileTypeFilter?.SelectMany(f =>
            {
                // We check for OS version outside of the lambda, it's safe.
#pragma warning disable CA1416
                if (f.AppleUniformTypeIdentifiers?.Any() == true)
                {
                    return(f.AppleUniformTypeIdentifiers.Select(id => UTType.CreateFromIdentifier(id)));
                }
                if (f.MimeTypes?.Any() == true)
                {
                    return(f.MimeTypes.Select(id => UTType.CreateFromMimeType(id)));
                }
                return(Array.Empty <UTType>());

#pragma warning restore CA1416
            })
                              .Where(id => id is not null)
                              .ToArray() ?? new[]
            {
                UTTypes.Content,
                UTTypes.Item,
                UTTypes.Data
            };
            documentPicker = new UIDocumentPickerViewController(allowedUtis !, false);
        }
        else
        {
            var allowedUtis = options.FileTypeFilter?.SelectMany(f => f.AppleUniformTypeIdentifiers ?? Array.Empty <string>())
                              .ToArray() ?? new[]
            {
                UTTypeLegacy.Content,
                UTTypeLegacy.Item,
                "public.data"
            };
            documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Open);
        }

        using (documentPicker)
        {
            if (OperatingSystem.IsIOSVersionAtLeast(13))
            {
                documentPicker.DirectoryUrl = GetUrlFromFolder(options.SuggestedStartLocation);
            }

            if (OperatingSystem.IsIOSVersionAtLeast(11, 0))
            {
                documentPicker.AllowsMultipleSelection = options.AllowMultiple;
            }

            var urls = await ShowPicker(documentPicker);

            return(urls.Select(u => new IOSStorageFile(u)).ToArray());
        }
    }
        /// <summary>
        /// File picking implementation
        /// </summary>
        /// <param name="allowedTypes">list of allowed types; may be null</param>
        /// <returns>picked file data, or null when picking was cancelled</returns>
        private Task <FileData> PickMediaAsync(string[] allowedTypes)
        {
            var id  = GetRequestId();
            var tcs = new TaskCompletionSource <FileData>(id);

            if (Interlocked.CompareExchange(ref completionSource, tcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            allowedTypes ??= new[]
            {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            // NOTE: Importing (UIDocumentPickerMode.Import) makes a local copy of the document,
            // while opening (UIDocumentPickerMode.Open) opens the document directly.
            // We do the first, so the user has to read the file immediately.
            var documentPicker = new UIDocumentPickerViewController(allowedTypes, UIDocumentPickerMode.Import);

            documentPicker.DidPickDocument       += DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled          += DocumentPicker_WasCancelled;
            documentPicker.DidPickDocumentAtUrls += DocumentPicker_DidPickDocumentAtUrls;

            GetActiveViewController().PresentViewController(documentPicker, true, null);
            return(tcs.Task);
        }
 private static void Pvc_WasCancelled(object sender, EventArgs e)
 {
     tcs.TrySetResult(null);
     tcs = null;
     pvc.Dispose();
     pvc = null;
 }
Exemple #11
0
        /// <summary>
        /// 选择文件
        /// </summary>
        /// <param name="p_allowMultiple">是否多选</param>
        /// <param name="p_allowedTypes"></param>
        /// <returns></returns>
        Task <List <FileData> > PickFiles(bool p_allowMultiple, string[] p_allowedTypes)
        {
            var allowedUtis = (p_allowedTypes != null) ? p_allowedTypes : new string[]
            {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            // NOTE: Importing (UIDocumentPickerMode.Import) makes a local copy of the document,
            // while opening (UIDocumentPickerMode.Open) opens the document directly. We do the
            // first, so the user has to read the file immediately.
            var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Import);

            documentPicker.DidPickDocument       += DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled          += DocumentPicker_WasCancelled;
            documentPicker.DidPickDocumentAtUrls += DocumentPicker_DidPickDocumentAtUrls;
            // 多选
            if (p_allowMultiple)
            {
                documentPicker.AllowsMultipleSelection = true;
            }

            UIViewController viewController = GetActiveViewController();

            viewController.PresentViewController(documentPicker, true, null);

            _tcs = new TaskCompletionSource <List <FileData> >();
            return(_tcs.Task);
        }
        public Task <PlatformDocument> DisplayImportAsync()
        {
            var taskCompletionSource = new TaskCompletionSource <PlatformDocument>();
            var docPicker            = new UIDocumentPickerViewController(allUTTypes, UIDocumentPickerMode.Import);

            docPicker.DidPickDocument += (sender, e) =>
            {
                CompleteTaskUsing(taskCompletionSource, e.Url);
            };
            docPicker.DidPickDocumentAtUrls += (sender, e) =>
            {
                CompleteTaskUsing(taskCompletionSource, e?.Urls[0]);
            };
            docPicker.WasCancelled += (sender, e) =>
            {
                taskCompletionSource.SetResult(null);
            };

            var window             = UIApplication.SharedApplication.KeyWindow;
            var rootViewController = window.RootViewController;

            rootViewController?.PresentViewController(docPicker, true, null);
            var presentationPopover = docPicker.PopoverPresentationController;

            presentationPopover.SourceView = rootViewController.View;
            presentationPopover.PermittedArrowDirections = 0;
            presentationPopover.SourceRect = rootViewController.View.Frame;

            return(taskCompletionSource.Task);
        }
Exemple #13
0
 public static void SetShowFileExtensions(this UIDocumentPickerViewController picker)
 {
     if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
     {
         return;
     }
     picker.ShouldShowFileExtensions = true;
 }
Exemple #14
0
 public static void SetAllowsMultipleSelection(this UIDocumentPickerViewController picker, bool isAllowed)
 {
     if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
     {
         return;
     }
     picker.AllowsMultipleSelection = isAllowed;
 }
Exemple #15
0
        public void OpenDocPicker(UIButton sender)
        {
            UIDocumentPickerViewController vc = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Open);

            vc.WasCancelled    += OnPickerCancel;
            vc.DidPickDocument += DidPickDocumentForOpen;
            PresentViewController(vc, true, null);
        }
        /// <summary>
        /// Launches the file picker
        /// </summary>
        /// <param name="sender">Button object that was pressed</param>
        /// <param name="ea">Event Arguments</param>
        void ChooseFilesButton_TouchUpInside(object sender, EventArgs ea)
        {
            string[] documentTypes = new string[] { UTType.Data, UTType.Content };
            UIDocumentPickerViewController filePicker = new UIDocumentPickerViewController(documentTypes, UIDocumentPickerMode.Import);

            filePicker.WasCancelled          += CancelFilesView;
            filePicker.DidPickDocumentAtUrls += FinishedSelectingImageFromFiles;

            NavigationController.PresentViewController(filePicker, true, null);
        }
Exemple #17
0
        private void LoadPressed(UIButton sender)
        {
            var picker = new UIDocumentPickerViewController(new string[] { "com.apple.xamarin-shot.worldmap" }, UIDocumentPickerMode.Open)
            {
                AllowsMultipleSelection = false,
                Delegate = this,
            };

            this.PresentViewController(picker, true, null);
        }
Exemple #18
0
        private async Task <StorageFile> DoPickSingleFileAsync()
        {
            _picker = new UIDocumentPickerViewController(_fileTypes.ToArray(), UIDocumentPickerMode.Open);
            _picker.PresentViewController(_picker, true, () => {
                _handle.Set();
            });
            _handle.WaitOne();

            return(new StorageFile(_uri));
        }
Exemple #19
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.
            status.Text     = device.State.ToString();
            deviceName.Text = device.Name;
            deviceId.Text   = device.Id.ToString();
            var picker = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Open);

            picker.WasCancelled += Picker_WasCancelled;

            uploadFile.TouchUpInside += delegate
            {
                picker.DidPickDocumentAtUrls += (object s, UIDocumentPickedAtUrlsEventArgs e) =>
                {
                    Console.WriteLine("url = {0}", e.Urls[0].AbsoluteString);
                    //bool success = await MoveFileToApp(didPickDocArgs.Url);
                    var    success   = true;
                    string filename  = e.Urls[0].LastPathComponent;
                    string extension = Path.GetExtension(filename);;
                    string msg       = success ? string.Format("Successfully imported file '{0}'", filename) : string.Format("Failed to import file '{0}'", filename);
                    // Some invaild file url returns null
                    NSData data = NSData.FromUrl(e.Urls[0]);
                    if (data != null)
                    {
                        byte[] dataBytes = new byte[data.Length];

                        System.Runtime.InteropServices.Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length));

                        for (int i = 0; i < dataBytes.Length; i++)
                        {
                            Console.WriteLine(dataBytes[i]);
                        }
                    }

                    Console.WriteLine(data + "Completed");

                    var alertController = UIAlertController.Create("import", msg, UIAlertControllerStyle.Alert);
                    var okButton        = UIAlertAction.Create("OK", UIAlertActionStyle.Default, (obj) =>
                    {
                        alertController.DismissViewController(true, null);
                    });
                    alertController.AddAction(okButton);
                    PresentViewController(alertController, true, null);
                };
                PresentViewController(picker, true, null);
            };

            updateFirmware.TouchUpInside += delegate {
                FirmwareUpdaterDelegate firmwareUpdater = new FirmwareUpdater(device.NativeDevice as CBPeripheral);
                firmwareUpdater.Start();
            };
        }
Exemple #20
0
        /// <summary>
        /// File picking implementation
        /// </summary>
        /// <param name="allowedTypes">list of allowed types; may be null</param>
        /// <returns>picked file data, or null when picking was cancelled</returns>
        private Task <FileData> PickMediaAsync(string[] allowedTypes)
        {
            var id = this.GetRequestId();

            var ntcs = new TaskCompletionSource <FileData>(id);

            if (Interlocked.CompareExchange(ref this.completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            var allowedUtis = new string[]
            {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            if (allowedTypes != null)
            {
                allowedUtis = allowedTypes;
            }

            // NOTE: Importing (UIDocumentPickerMode.Import) makes a local copy of the document,
            // while opening (UIDocumentPickerMode.Open) opens the document directly. We do the
            // first, so the user has to read the file immediately.
            var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Import);

            documentPicker.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
            documentPicker.DidPickDocument       += this.DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled          += this.DocumentPicker_WasCancelled;
            documentPicker.DidPickDocumentAtUrls += this.DocumentPicker_DidPickDocumentAtUrls;

            UIViewController viewController = GetActiveViewController();

            viewController.PresentViewController(documentPicker, true, null);

            this.Handler = (sender, args) =>
            {
                var tcs = Interlocked.Exchange(ref this.completionSource, null);

                tcs?.SetResult(new FileData(
                                   args.FilePath,
                                   args.FileName,
                                   () =>
                {
                    return(new FileStream(args.FilePath, FileMode.Open, FileAccess.Read));
                }));
            };

            return(this.completionSource.Task);
        }
Exemple #21
0
        static Task <IEnumerable <FileResult> > PlatformPickAsync(PickOptions options, bool allowMultiple = false)
        {
            if (allowMultiple && !Platform.HasOSVersion(11, 0))
            {
                throw new FeatureNotSupportedException("Multiple file picking is only available on iOS 11 or later.");
            }

            var allowedUtis = options?.FileTypes?.Value?.ToArray() ?? new string[]
            {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            var tcs = new TaskCompletionSource <IEnumerable <FileResult> >();

            // Note: Importing (UIDocumentPickerMode.Import) makes a local copy of the document,
            // while opening (UIDocumentPickerMode.Open) opens the document directly. We do the
            // latter, so the user accesses the original file.
            var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Open);

            documentPicker.AllowsMultipleSelection = allowMultiple;
            documentPicker.Delegate = new PickerDelegate
            {
                PickHandler = urls =>
                {
                    try
                    {
                        // there was a cancellation
                        if (urls?.Any() ?? false)
                        {
                            tcs.TrySetResult(urls.Select(url => new UIDocumentFileResult(url)));
                        }
                        else
                        {
                            tcs.TrySetResult(Enumerable.Empty <FileResult>());
                        }
                    }
                    catch (Exception ex)
                    {
                        // pass exception to task so that it doesn't get lost in the UI main loop
                        tcs.SetException(ex);
                    }
                }
            };

            var parentController = Platform.GetCurrentViewController();

            parentController.PresentViewController(documentPicker, true, null);

            return(tcs.Task);
        }
Exemple #22
0
        private void MoveToDocPicker(UIButton sender)
        {
            if (TryShowFileNotExistsError())
            {
                return;
            }

            UIDocumentPickerViewController vc = new UIDocumentPickerViewController(documentURL, UIDocumentPickerMode.MoveToService);

            vc.WasCancelled    += OnPickerCancel;
            vc.DidPickDocument += DidPickDocumentForMove;
            PresentViewController(vc, true, null);
        }
        public void DidPickDocumentPicker(UIDocumentMenuViewController documentMenu, UIDocumentPickerViewController documentPicker)
        {
            documentPicker.DidPickDocument += this.DocumentPicker_DidPickDocument;

            documentPicker.DidPickDocumentAtUrls += (sender, e) =>
            {
                this.Picker_DidPickDocuments((UIDocumentPickerViewController)sender, e.Urls);
            };

            documentPicker.WasCancelled += this.DocumentPicker_WasCancelled;

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(documentPicker, true, null);
        }
        private Task <FileData> TakeMediaAsync(string[] allowedTypes)
        {
            var id = GetRequestId();

            var ntcs = new TaskCompletionSource <FileData> (id);

            if (Interlocked.CompareExchange(ref _completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            var allowedUtis = new string [] {
                UTType.Content,
                UTType.Item,
                "public.data"
            };

            if (allowedTypes != null)
            {
                allowedUtis = allowedTypes;
            }

            // NOTE: Importing makes a local copy of the document, while opening opens the document directly
            var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Import);

            //var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Open);

            documentPicker.DidPickDocument       += DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled          += DocumentPicker_WasCancelled;
            documentPicker.DidPickDocumentAtUrls += DocumentPicker_DidPickDocumentAtUrls;

            UIViewController viewController = GetActiveViewController();

            viewController.PresentViewController(documentPicker, true, null);

            Handler = null;

            Handler = (s, e) =>
            {
                var tcs = Interlocked.Exchange(ref _completionSource, null);

                tcs?.SetResult(new FileData(e.FilePath, e.FileName, () =>
                {
                    return(new FileStream(e.FilePath, FileMode.Open, FileAccess.Read));
                }));
            };

            return(_completionSource.Task);
        }
Exemple #25
0
        public void DidPickDocument(UIDocumentPickerViewController controller, NSUrl[] urls)
        {
            var selected = urls.FirstOrDefault();

            if (selected != null)
            {
                this.FetchArchivedWorldMap(selected, (data, error) =>
                {
                    if (error == null && data != null)
                    {
                        this.LoadWorldMap(data);
                    }
                });
            }
        }
Exemple #26
0
        private async Task OpenMediaPicker()
        {
            if (PresentedViewController != null)
            {
                await DismissViewControllerAsync(false);
            }

            // Allow the Document picker to select a range of document types
            var allowedUTIs = new string[] { UTType.Audio };

            // Display the picker
            docPicker = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Import);
            docPicker.AllowsMultipleSelection = false;
            docPicker.DidPickDocumentAtUrls  += DocPicker_DidPickDocumentAtUrls;

            await PresentViewControllerAsync(docPicker, false);
        }
        public Task <FolderData> PickFolder()
        {
            var id = this.GetRequestId();

            var ntcs = new TaskCompletionSource <FolderData>(id);

            if (Interlocked.CompareExchange(ref this.tcs_folderData, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }

            var allowedUtis = new string[]
            {
                //UTType.Content,
                //UTType.Item,
                "public.folder"
            };

            // NOTE: Importing (UIDocumentPickerMode.Import) makes a local copy of the document,
            // while opening (UIDocumentPickerMode.Open) opens the document directly. We do the
            // second one here.
            var documentPicker = new UIDocumentPickerViewController(allowedUtis, UIDocumentPickerMode.Open);

            documentPicker.DidPickDocument       += this.DocumentPicker_DidPickDocument;
            documentPicker.WasCancelled          += this.DocumentPicker_WasCancelled;
            documentPicker.DidPickDocumentAtUrls += this.DocumentPicker_DidPickDocumentAtUrls;

            UIViewController viewController = GetActiveViewController();

            viewController.PresentViewController(documentPicker, true, null);

            this.Handler = (sender, args) =>
            {
                var tcs = Interlocked.Exchange(ref this.tcs_folderData, null);
                //re-using file picker, the path is here
                var folder = new FolderData()
                {
                    FolderPath = args.FilePath,
                    FolderName = args.FileName
                };
                tcs?.SetResult(folder);
            };

            return(this.tcs_folderData.Task);
        }
        public static Task <IStorageFile> PickSingleFileAsync(IList <string> fileTypes)
        {
            tcs = new TaskCompletionSource <IStorageFile>();

            pvc = new UIDocumentPickerViewController(fileTypes?.ToArray() ?? new string[] { UTType.Content, UTType.Item, "public.data" }, UIDocumentPickerMode.Open)
            {
                AllowsMultipleSelection = false
            };
            pvc.DidPickDocument       += Pvc_DidPickDocument;
            pvc.WasCancelled          += Pvc_WasCancelled;
            pvc.DidPickDocumentAtUrls += Pvc_DidPickDocumentAtUrls;

            UIViewController viewController = GetActiveViewController();

            viewController.PresentViewController(pvc, true, null);

            return(tcs.Task); //Task.FromResult<IStorageFile>(new StorageFile(_uri));
        }
    private Task <NSUrl[]> ShowPicker(UIDocumentPickerViewController documentPicker)
    {
        var tcs = new TaskCompletionSource <NSUrl[]>();

        documentPicker.Delegate = new PickerDelegate(urls => tcs.TrySetResult(urls));

        if (documentPicker.PresentationController != null)
        {
            documentPicker.PresentationController.Delegate =
                new UIPresentationControllerDelegate(() => tcs.TrySetResult(Array.Empty <NSUrl>()));
        }

        var controller = _view.Window?.RootViewController ?? throw new InvalidOperationException("RootViewController wasn't initialized");

        controller.PresentViewController(documentPicker, true, null);

        return(tcs.Task);
    }
Exemple #30
0
        private void OpenPicker()
        {
            var vc1 = Platform.GetCurrentUIViewController();

            var allowedUTIs = new string[] { UTType.UTF8PlainText,
                                             UTType.PlainText,
                                             UTType.RTF,
                                             UTType.PNG,
                                             UTType.Text,
                                             UTType.PDF,
                                             UTType.Image };


            var pvc = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Import);

            vc1.PresentViewController(pvc, true, null);

            pvc.DidPickDocument       += Pvc_DidPickDocument;
            pvc.DidPickDocumentAtUrls += Pvc_DidPickDocumentAtUrls;
        }
		public void OpenDocPicker(UIButton sender)
		{
			UIDocumentPickerViewController vc = new UIDocumentPickerViewController (allowedUTIs, UIDocumentPickerMode.Open);
			SetupDelegateThenPresent (vc);
		}
		private void MoveToDocPicker(UIButton sender)
		{
			UIDocumentPickerViewController vc = new UIDocumentPickerViewController (documentURL, UIDocumentPickerMode.MoveToService);
			SetupDelegateThenPresent (vc);
		}
		private void SetupDelegateThenPresent(UIDocumentPickerViewController docPickerViewController)
		{
			docPickerViewController.WasCancelled += OnPickerCancel;
			docPickerViewController.DidPickDocument += OnDocumentPicked;
			PresentViewController (docPickerViewController, true, null);
		}
		void Unsibscribe(UIDocumentPickerViewController picker)
		{
			picker.WasCancelled -= OnPickerCancel;
			picker.DidPickDocument -= OnDocumentPicked;
		}
		public void ExportToDocPicker(UIButton sender)
		{
			UIDocumentPickerViewController vc = new UIDocumentPickerViewController (documentURL, UIDocumentPickerMode.ExportToService);
			SetupDelegateThenPresent (vc);
		}
		public void OpenDocPicker(UIButton sender)
		{
			UIDocumentPickerViewController vc = new UIDocumentPickerViewController (allowedUTIs, UIDocumentPickerMode.Open);
			vc.WasCancelled += OnPickerCancel;
			vc.DidPickDocument += DidPickDocumentForOpen;
			PresentViewController (vc, true, null);
		}
		private void MoveToDocPicker(UIButton sender)
		{
			if (TryShowFileNotExistsError ())
				return;

			UIDocumentPickerViewController vc = new UIDocumentPickerViewController (documentURL, UIDocumentPickerMode.MoveToService);
			vc.WasCancelled += OnPickerCancel;
			vc.DidPickDocument += DidPickDocumentForMove;
			PresentViewController (vc, true, null);
		}