ios - 从共享扩展中检索 imageURL

标签 ios swift xcode imageurl share-extension

我正在尝试获取 ios 共享扩展用于 action sheet 中生成的缩略图的 imageURL

我正在检索 URL 正常,但似乎无法弄清楚如何获取 imageURL

这是我如何获得正常的 URL,

 if let item = extensionContext?.inputItems.first as? NSExtensionItem {
        if let itemProvider = item.attachments?.first as? NSItemProvider {      
            if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeItem as String) {
                itemProvider.loadItem(forTypeIdentifier: kUTTypeItem as String, options: nil, completionHandler: { (url, error) -> Void in
                    if let shareURL = url as? NSURL {

                        let components = URLComponents(url:shareURL as URL, resolvingAgainstBaseURL: true)
                        if  let host = components?.host { self.shareTitle = host }
                        self.shareURL = shareURL.absoluteString!                            
                        self.POSTShareData(completion: nil)
                    }
                    self.extensionContext?.completeRequest(returningItems: [], completionHandler:nil)
                })
            }
        }
    }

我曾尝试将 typeIdentifier 更改为 kUTTypeImage 但无济于事。我将我的 info.plist 设置为 NSExtensionActivationRuleTRUEPREDICATE 以查看我可以检索的内容。我在想也许我必须在 .plist 中更加明确??

我的目标是 iOS 9.3

最佳答案

解决方法是您可以将该 URL 链接存储在通用 UserDefaults 中

例如:- let defaults = UserDefaults(suiteName: "group.com.common.Notification")

然后在应用内或扩展中访问它

关于ios - 从共享扩展中检索 imageURL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388297/

相关文章:

ios - 如何将此字符串 @"base+unit1+unit2(unit3+unit4)"转换为数组

iphone - 从完成的 ASIHTTPRequest 获取 postValue

swift - 当此代码运行时,为什么没有在 Vapor 中创建数据透视表条目?

ios - 实例成员不能用于类 NSObject 的类型

Xcode 11,Command CodeSign 失败,退出代码为非零

ios - 验证 bundle 时,错误提示 bundle 无效,但我确保它匹配

ios - IBM Worklight - iOS 7 状态栏与应用程序的 HTML 重叠

ios - 如何修复 AFNetworking 3.1 中的内存泄漏?

swift - 外围设备未连接 - Swift

objective-c - 添加方法后应用程序无法启动(Xcode 7.2)