Bug 59551 - UIDocumentPickerViewController.DidPickDocument is not raised on iOS 11
Summary: UIDocumentPickerViewController.DidPickDocument is not raised on iOS 11
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.99 (xcode9)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-18 11:01 UTC by Michael Rumpler
Modified: 2017-12-06 07:22 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Michael Rumpler 2017-09-18 11:01:55 UTC
I use a UIDocumentPickerViewController to open files. This worked fine until iOS 10.3.3, but the event handler for DidPickDocument is not called anymore on iOS 11 devices (or simulator).

My code is:

	var allowedUTIs = new string[] {
		UTType.Data,
	};

	picker = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Import);
	picker.DidPickDocument += Picker_DidPickDocument;
	picker.WasCancelled += Picker_WasCancelled;
	if (picker.View != null)
		picker.View.BackgroundColor = UIColor.White;

	var mainController = UIApplication.SharedApplication.KeyWindow.RootViewController;
	mainController.PresentViewController(picker, false, (Action)null);

My handler Picker_DidPickDocument is not called on iOS 11. If I cancel the picker, then Picker_WasCancelled does work also on iOS 11.

I did not attach a repro project, because the same happens in your own DocPicker sample available on https://github.com/xamarin/ios-samples/tree/master/ios8/DocPicker
Comment 1 Michael Rumpler 2017-09-19 08:29:32 UTC
I found out that Apple deprecated didPickDocumentAt in iOS11. https://developer.apple.com/documentation/uikit/uidocumentpickerdelegate/1618680-documentpicker

I just installed VS2017 Preview but it seems like the new didPickDocumentsAt (plural) has not been added yet to Xamarin.iOS even in Preview. Or do I have to install anything else on Windows to get the iOS 11 APIs?

I downloaded Xamarin.iOS 11.0.0.0 from https://bosstoragemirror.azureedge.net/wrench/macios-mac-xcode9/15/152b654a628e4ea0e6afe8a638a0bada1f3f4be4/xamarin.ios-11.0.0.0.pkg as of ticket 59247. I don't know if there is a respective Windows version somewhere.

I'm currently running:

Windows:

Microsoft Visual Studio Professional 2017 Preview (2)
Version 15.4.0 Preview 2.0
VisualStudio.15.Preview/15.4.0-pre.2.0+26906.1
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Professional

Mono Debugging for Visual Studio   4.7.4-pre (c2d89eb)
Support for debugging Mono processes with Visual Studio.

Xamarin   4.7.0.934 (d68a92f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.5.0.15 (HEAD/cf9532456)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.14.0.26 (416f778)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Mac:

=== Visual Studio Professional 2017 for Mac (Preview) ===

Version 7.2 Preview (7.2 build 583)
Installation UUID: 015206d2-825e-420c-96b7-9d4a3b803a70
Runtime:
	Mono 5.4.0.174 (2017-06/1afb931de69) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504000174

=== Apple Developer Tools ===

Xcode 9.0 (13238.4)         also tried 8.3.3
Build 9M214v

=== Xamarin.iOS ===

Version: 11.0.0.0 (Visual Studio Professional)
Hash: 152b654a
Branch: xcode9
Build date: 2017-09-15 02:25:56-0400

=== Build Information ===

Release ID: 702000583
Git revision: 861d3eb8f64655762b85235dde49874645208f51
Build date: 2017-09-05 15:23:48-04
Xamarin addins: 838dc0d12bdbb0407ea44b7bfd11fbe30ddac07b
Build lane: monodevelop-lion-d15-4

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jun 15 17:36:27 PDT 2017
    root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
Comment 2 Michael Rumpler 2017-09-19 09:39:14 UTC
I could work around it when I used a delegate with this method:

    [Export("documentPicker:didPickDocumentsAtURLs:")]
    void DidPickDocument(UIDocumentPickerViewController controller, NSUrl[] urls)
Comment 3 Manuel de la Peña [MSFT] 2017-09-19 10:21:58 UTC
Thanks for the bug report. We just landed the work we did for Xcode 9 in master, which means that you will soon be able to use the new API. As you can see: "documentPicker:didPickDocumentsAtURLs:" was added to the delegate as void DidPickDocument (UIDocumentPickerViewController controller, NSUrl[] urls);

https://github.com/xamarin/xamarin-macios/blob/master/src/uikit.cs#L16729 

You should be able to use the new API in the upcoming Preview/Release. Will close the bug since the code is present YET not released.
Comment 4 Alain 2017-11-01 07:08:38 UTC
Hi,

can you tell me what needs to be done to make it work because I now see that our customers have this problem and I am at the latest version of Xamarin.IOS 11. See below :

=== Visual Studio Professional 2017 for Mac (Preview) ===

Version 7.3 Preview (7.3 build 708)
Installation UUID: af98516b-7b3c-413e-ba1b-95a1baeaccc6
Runtime:
	Mono 5.4.1.4 (2017-06/c6605763a36) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504010004

=== NuGet ===

Version : 4.3.1.4445

=== .NET Core ===

Runtime : Non installé
SDK : Non installé
SDK MSBuild : /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version : 1.6.0
Emplacement : /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version : 8.1.0.21 (Visual Studio Professional)
Android SDK: /Users/macbookrogister/Library/Developer/Xamarin/android-sdk-macosx
	Versions Android prises en charge :
		6.0(Niveau d’API 23)
		7.1(Niveau d’API 25)

Version des outils du SDK : 25.2.5
Version des outils de plateforme du SDK : 25.0.5
Version des outils de génération du SDK : 25.0.1

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Code EPL d'Android Designer disponible ici :
https://github.com/xamarin/AndroidDesigner.EPL

=== Apple Developer Tools ===

Xcode 9.0.1 (13249)
Build 9A1004

=== Xamarin.iOS ===

Version: 11.2.0.11 (Visual Studio Professional)
Hash: 2f8bbec0
Branch: d15-4-xi
Build date: 2017-10-05 20:56:05-0400

=== Xamarin.Mac ===

Version: 3.99.9.11 (Visual Studio Professional)

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 703000708
Git revision: 8280d69b96e85b524aeda11210fdc2e54cc7f30c
Build date: 2017-10-15 06:04:33-04
Xamarin addins: b7cbc5837cf6fa3ba63d613a47480cc4ecd4759c
Build lane: monodevelop-lion-d15-5

=== Operating System ===

Mac OS X 10.13.0
Darwin 17.0.0 Darwin Kernel Version 17.0.0
    Thu Aug 24 21:48:19 PDT 2017
    root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64
Comment 5 Michael Rumpler 2017-11-02 07:17:15 UTC
Apple added a new call DidPickDocuments (with a "s" at the end) in iOS 11 and immediately deprecated DidPickDocument and doesn't call it anymore. Therefore you need to handle both to run on all iOS versions.

Here is what I did:


		picker = new UIDocumentPickerViewController(allowedUTIs, UIDocumentPickerMode.Import);
		picker.DidPickDocument += (sender, e) => {
			Picker_DidPickDocument((UIDocumentPickerViewController)sender, e.Url);
		};
		picker.DidPickDocumentAtUrls += (sender, e) => {
			Picker_DidPickDocuments((UIDocumentPickerViewController)sender, e.Urls);
		};
		picker.WasCancelled += (sender, e) => DisposePicker();


	private void Picker_DidPickDocuments(UIDocumentPickerViewController controller, NSUrl[] urls)
	{
		foreach (var url in urls)
			Picker_DidPickDocument(controller, url, false);

		DisposePicker();
	}

	private void Picker_DidPickDocument(UIDocumentPickerViewController controller, NSUrl url, bool dispose = true)
	{
		...

		if (dispose)
			DisposePicker();
	}
Comment 6 Alain 2017-11-02 13:36:57 UTC
Ok, thanks.

with your example, it works fine now.

Alain
Comment 7 Matt Ingle 2017-12-05 22:58:12 UTC
Is UIKit.UIDocumentPickerViewController.DidPickDocumentAtUrls in Xamarin.iOS equivalent to the new UIDocumentPickerDelegate.DidPickDocumentsAt (plural) in iOS 11+ that replaces DidPickDocumentAt (singular) in iOS 8-11?
Comment 8 Michael Rumpler 2017-12-06 07:22:11 UTC
Thats what Manuel wrote in Comment 3.