Bug 58081 - IUIDropSession.Completion first arg should be a Class
Summary: IUIDropSession.Completion first arg should be a Class
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.99 (xcode9)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Xcode9
Assignee: Vincent Dondain [MSFT]
Depends on:
Reported: 2017-07-11 16:27 UTC by Frank A. Krueger
Modified: 2017-07-13 22:45 UTC (History)
2 users (show)

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:

Description Frank A. Krueger 2017-07-11 16:27:37 UTC
There is currently no way to use the "Completion" method of IUIDropSession.

The first arg in the Apple docs is a class: https://developer.apple.com/documentation/uikit/uidropsession/2891058-loadobjectsofclass?language_2

However, it is bound to: INSItemProviderReading


I tried passing:

			class StringReader : NSObject, INSItemProviderReading
				[Export ("readableTypeIdentifiersForItemProvider")]
				static NSArray ReadableTypeIdentifiers ()
					Console.WriteLine ($"ReadableTypeIdentifiers");
					return NSArray.FromObjects (new NSString ("public.text"));

				[Export ("objectWithItemProviderData:typeIdentifier:error:")]
				static NSObject ObjectWithItemProviderData (NSData data, NSString typeIdentifier, out NSError error)
					Console.WriteLine ($"ObjectWithItemProviderData ({data}, {typeIdentifier})");
					error = null;
					return data.ToString (NSStringEncoding.UTF8);

But that of course doesn't work because it's not a Class.
Comment 1 Vincent Dondain [MSFT] 2017-07-11 20:29:24 UTC
I agree that the "Completion" method (that will likely be renamed) should take a Class instead of INSItemProviderReading.

Similar to:

[Export ("canLoadObjectsOfClass:")]
bool CanLoadObjectsOfClass (Class itemProviderReadingClass);

Swift code as reference:

session.loadObjects(ofClass: UIImage.self) { imageItems in
        let images = imageItems as! [UIImage]

             If you do not employ the loadObjects(ofClass:completion:) convenience
             method of the UIDropSession class, which automatically employs
             the main thread, explicitly dispatch UI work to the main thread.
             For example, you can use `DispatchQueue.main.async` method.
        self.imageView.image = images.first
Comment 2 Vincent Dondain [MSFT] 2017-07-11 20:41:02 UTC
In progress: https://github.com/xamarin/xamarin-macios/pull/2314
Comment 3 Vincent Dondain [MSFT] 2017-07-13 22:45:55 UTC
PR merged to xcode9 branch.