【发布时间】:2021-12-06 07:25:06
【问题描述】:
就像post 一样,我想通过应用间拖放交互接收 pdf 文档。当我将我的 pdf 文件拖到我的组件上时,IUIDropSession 包含一个标识符 com.adobe.pdf,PerformDrop 也被调用,但 LoadPdfs 不是。应用程序崩溃。为什么?
[Export("dropInteraction:canHandleSession:")]
public bool CanHandleSession(UIDropInteraction interaction, IUIDropSession session)
{
return session.CanLoadObjects(typeof(PDFDocument)); // This returns true
}
[Export("dropInteraction:sessionDidUpdate:")]
public UIDropProposal SessionDidUpdate(UIDropInteraction interaction, IUIDropSession session)
{
return new UIDropProposal(UIDropOperation.Copy);
}
[Export("dropInteraction:performDrop:")]
public void PerformDrop(UIDropInteraction interaction, IUIDropSession session)
{
session.LoadObjects<PDFDocument>(LoadPdfs); // CRASH WHEN EXECUTING THIS LINE
}
private void LoadPdfs(PDFDocument[] items)
{
// This is not called
}
PdfDocument 是这个类的位置
class PDFDocument : NSObject, INSItemProviderReading
{
string identifier;
NSData data;
public PDFDocument(NSData pdfData, string typeIdentifier)
{
data = pdfData;
identifier = typeIdentifier;
}
[Export("objectWithItemProviderData:typeIdentifier:error:")]
static public INSItemProviderReading GetObject(NSData data, string indentifier, NSError error)
{
return new PDFDocument(data, indentifier);
}
[Export("readableTypeIdentifiersForItemProvider")]
static public string[] ReadableTypeIdentifiers => new string[]
{
"com.adobe.pdf"
};
[Export("withItemProviderData")]
public static object WithItemProviderData(NSData data, string typeIdentifier)
=> new PDFDocument(data, typeIdentifier);
}
崩溃:
=================================================================
Native Crash Reporting
=================================================================
Got a segv while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
0x105c485ac - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/Frameworks/Mono.framework/Mono : mono_dump_native_crash_info
0x105c3e724 - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/Frameworks/Mono.framework/Mono : mono_handle_native_crash
0x105c4ca2c - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/Frameworks/Mono.framework/Mono : mono_sigsegv_signal_handler_debug
0x1e0b1fd50 - /usr/lib/system/libsystem_platform.dylib : <redacted>
0x104e29a34 - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/TestFilePicker.iOS : xamarin_get_block_descriptor
0x104e2976c - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/TestFilePicker.iOS : xamarin_get_block_descriptor
0x104e296b4 - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/TestFilePicker.iOS : xamarin_get_block_descriptor
0x100d41aac - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/TestFilePicker.iOS :
0x100d418c8 - /private/var/containers/Bundle/Application/6363E6AA-015A-4276-8203-4C138D1F9A22/TestFilePicker.iOS.app/TestFilePicker.iOS :
0x1898b7db4 - /System/Library/Frameworks/Foundation.framework/Foundation : <redacted>
0x189927030 - /System/Library/Frameworks/Foundation.framework/Foundation : <redacted>
0x187d4e2ec - /usr/lib/system/libdispatch.dylib : <redacted>
0x187d4f2f0 - /usr/lib/system/libdispatch.dylib : <redacted>
0x187cf554c - /usr/lib/system/libdispatch.dylib : <redacted>
0x187cf5ff0 - /usr/lib/system/libdispatch.dylib : <redacted>
0x187cffae4 - /usr/lib/system/libdispatch.dylib : <redacted>
0x1e0b2af38 - /usr/lib/system/libsystem_pthread.dylib : _pthread_wqthread
0x1e0b2aaa4 - /usr/lib/system/libsystem_pthread.dylib : start_wqthread
=================================================================
【问题讨论】:
-
这看起来不像
LoadObjects- docs.microsoft.com/es-es/dotnet/api/… 的正确方法签名 -
是的,它是一种扩展方法。 @Jason 你知道如何在你引用的文档中指定 LoadObjects 的第一个参数吗?
标签: c# ios xamarin drag-and-drop