PDF 的操作扩展



>我正在尝试使用扩展名在我的应用程序中打开pdf文件,我可以使用Xcode为图像提供的默认文件来显示图像,即使我能够在未设置激活规则时显示pdf,但是如果不指定我们在应用程序中使用的扩展类型,我们就无法发布应用程序。

我尝试了很多方法,但失败了 我根据堆栈溢出上的一些问题对 info.plist 进行了很少的更改,但 Xcode 抛出错误,说无法读取属性列表

<dict>
<key>NSExtensionActivationRule</key>
<string>
SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "com.adobe.pdf"
).@count == $extensionItem.attachments.@count
).@count == 1
</string>
</dict>

这是我的ActionViewController代码:

{

@IBOutlet weak var myPdfView: PDFView!
override func viewDidLoad() {
super.viewDidLoad()
// Get the item[s] we're handling from the extension context.
// For example, look for an image and place it into an image view.
// Replace this with something appropriate for the type[s] your extension supports.
for item in self.extensionContext!.inputItems as! [NSExtensionItem] {
for provider in item.attachments! {
if provider.hasItemConformingToTypeIdentifier(kUTTypePDF as String) {
// This is an image. We'll load it, then place it in our image view.
weak var weakPDFView = self.myPdfView
provider.loadItem(forTypeIdentifier: kUTTypePDF as String, options: nil, completionHandler: { (imageURL, error) in
OperationQueue.main.addOperation {
if let strongPDFView = weakPDFView {
if let imageURL = imageURL as? URL {
strongPDFView.document = PDFDocument(data: try! Data(contentsOf: imageURL))
}
}
}
})
break
}
}
}
}
@IBAction func done() {
// Return any edited content to the host app.
// This template doesn't do anything, so we just echo the passed in items.
self.extensionContext!.completeRequest(returningItems: self.extensionContext!.inputItems, completionHandler: nil)
}

}

Xcode 抛出错误,指出无法读取属性列表

错字。是的

</dict>

<dict/>

最新更新