kUTTypeURL undefined - 在Swift中使用未解析的标识符“kUTTypeURL”

时间:2021-01-09 06:30:48

I'm having trouble getting a sharing extension to work. I have the following in my sharing controller.

我无法获得共享扩展功能。我的共享控制器中有以下内容。

let item: NSExtensionItem = self.extensionContext.inputItems[0] as NSExtensionItem
let itemProvider: NSItemProvider = item.attachments[0] as NSItemProvider
var URL: NSString
if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL) {
  itemProvider.loadItemForTypeIdentifier(kUTTypeURL, options: nil, completionHandler:   {(url: NSURL, error: NSError) in
     URL = url.absoluteString
  })
}

self.extensionContext.completeRequestReturningItems(nil, completionHandler: nil)

This gives me the error Use of unresolved identifier 'kUTTypeURL' on the line if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL) {.

如果itemProvider.hasItemConformingToTypeIdentifier(kUTTypeURL){,这会给我错误使用行上未解析的标识符'kUTTypeURL'。

It seems to be defined as a constant in Swift, but I can't seem to access it. Is it part of an enum? Do I have to import something to get access to it?

它似乎被定义为Swift中的常量,但我似乎无法访问它。它是枚举的一部分吗?我是否必须导入一些内容才能访问它?

Thanks for your help.

谢谢你的帮助。

1 个解决方案

#1


23  

Just so this question has an answer:

就这样这个问题有一个答案:

Add import MobileCoreServices to your source file.

将导入MobileCoreServices添加到源文件中。

#1


23  

Just so this question has an answer:

就这样这个问题有一个答案:

Add import MobileCoreServices to your source file.

将导入MobileCoreServices添加到源文件中。