“Unexpected value class.”
.如果我尝试将其加载为id< NSSecureCoding> item和debug,我发现传入的对象确实只是页面的标题而不是URL.我如何阅读URL?
NSURL *pageURL = nil; for (NSExtensionItem *item in self.extensionContext.inputItems) { for (NSItemProvider *itemProvider in item.attachments) { if ([itemProvider hasItemConformingToTypeIdentifier: (NSString*) kUTTypeURL]) { [itemProvider loadItemForTypeIdentifier:(NSString*) kUTTypeURL options:nil completionHandler:^(id <NSSecureCoding> urlItem,NSError *error) { if ([((NSObject*)urlItem) isKindOfClass: [NSURL class]]) { pageURL = [((NSURL*)urlItem) absoluteString]; } }]; } } }
解决方法
loadItemForTypeIdentifier(_:options:completionHandler:)
你会看到:
The type information for the first parameter of your completionHandler
block should be set to the class of the expected type. For example,
when requesting text data,you might set the type of the first
parameter to NSString or NSAttributedString. An item provider can
perform simple type conversions of the data to the class you specify,
such as from NSURL to NSData or NSFileWrapper,or from NSData to
UIImage (in iOS) or NSImage (in OS X). If the data could not be
retrieved or coerced to the specified class,an error is passed to the
completion block’s.
也许你可以通过胁迫不同的类型进行实验?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。