gpt4 book ai didi

ios - 如何在 iOS 共享扩展中获取共享对象的文件名

转载 作者:可可西里 更新时间:2023-11-01 17:16:23 26 4
gpt4 key购买 nike

基本上我想从其他应用程序(例如 dropbox)检索文件(例如 pdf)以供以后存储和修改。

我为该任务编写了一个共享扩展,可以遍历 NSExtensionItem 并捕获我的文件 - 但我不知道它们的原始文件名。

我注意到其他应用程序获得了文件名 - 但它们是通过 iOS 中的“打开方式”功能调用的。

那么我如何在共享扩展名中获取文件名?

提前致谢。

最佳答案

您在收到的 URL 中将文件名作为 lastPathComponent:

    itemProvider!.first!.loadItemForTypeIdentifier(kUTTypeImage as String, options: nil, completionHandler: {
(provider, error) in
let url = provider as! NSURL

println(url)

let data = NSData(contentsOfURL: url)

let name = url.lastPathComponent!

...

// Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
})

关于ios - 如何在 iOS 共享扩展中获取共享对象的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29170619/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com