Xamarin 上的 NSItemProviderReading

NSItemProviderReading on Xamarin

要对 iOS 11 中的文件进行文件拖放,您需要实施 NSItemProviderReading,这里有 swift 的示例代码:iOS 11 dropInteraction performDrop for files

然而,如何在 Xamarin 中做到这一点,我想 class 定义应该是这样的,但是如何实现这些方法?

public class DocumentProvider : NSObject, INSItemProviderReading
{

}

您可以像这样实现 NSItemProviderReading

class MyItemProvider : UIView, INSItemProviderReading {

    [Export ("readableTypeIdentifiersForItemProvider")]
    public static string [] ReadableTypeIdentifiersForItemProvider => new string [] { "public.image", "public.data" }

    [Export ("objectWithItemProviderData:typeIdentifier:error:")]
    public static MyItemProvider GetObject (NSData data, string typeIdentifier, out NSError outError)
    {
        outError = null;
        switch (typeIdentifier) {
        case "public.image": return new ...;
        case "public.data": return new ...;
        default:
            outError = new NSError (...);
            return null;
        }
    }
}

参考:NSItemProviderReading requirements.