共享扩展加载whatsapp zip附件不起作用

发布于 2025-02-07 01:10:10 字数 2339 浏览 0 评论 0原文

我正在尝试阅读导出聊天zip文件,但是共享扩展名加载whatsapp zip附件不起作用。

我正在使用此代码 - :

 override func viewDidLoad() {
    super.viewDidLoad()

    getURL()
    
}

private func getURL() {
    let extensionItem = extensionContext?.inputItems.first as! NSExtensionItem
    let itemProvider = extensionItem.attachments?.first
    let zip_type = String(UTType.zip.identifier)
    if itemProvider!.hasItemConformingToTypeIdentifier(zip_type) {
        itemProvider!.loadItem(forTypeIdentifier: zip_type, options: nil, completionHandler: { (item, error) -> Void in
            guard let url = item as? NSURL else { return }
            OperationQueue.main.addOperation {
                print("url\(url)")
                self.path = url as URL

                do {
                    let unzipDirectory = try Zip.quickUnzipFile(self.path)
                    print("unzipDirectory\(unzipDirectory)")
                   
                    if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {

                        let fileURL = dir.appendingPathComponent(unzipDirectory.lastPathComponent)
                        print("fileURL\(fileURL)")
                        do {
                               let text2 = try String(contentsOf: fileURL, encoding: .utf8)
                            print(text2)
                           }
                           catch {/* error handling here */}
                }
            }
                catch {
                    print("Something went wrong")
                }

            }
        })
    } else {
        print("error")
    }
}
override func isContentValid() -> Bool {
    print("Hiii")
    // Do validation of contentText and/or NSExtensionContext attachments here
    return true
}

override func didSelectPost() {
    print("hello")
    self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
    
}

override func configurationItems() -> [Any]! {
    // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
    return []
}

在控制台错误中是:

[core] slcomposeserviceViewController获取附件coarsetype 0 [core] slcomposeserviceviewController并未为public.file-url

符合ItemProvider的附件。

I am trying to read Export chat Zip file but share extension loading a WhatsApp Zip attachment is not working.

I am using this code -:

 override func viewDidLoad() {
    super.viewDidLoad()

    getURL()
    
}

private func getURL() {
    let extensionItem = extensionContext?.inputItems.first as! NSExtensionItem
    let itemProvider = extensionItem.attachments?.first
    let zip_type = String(UTType.zip.identifier)
    if itemProvider!.hasItemConformingToTypeIdentifier(zip_type) {
        itemProvider!.loadItem(forTypeIdentifier: zip_type, options: nil, completionHandler: { (item, error) -> Void in
            guard let url = item as? NSURL else { return }
            OperationQueue.main.addOperation {
                print("url\(url)")
                self.path = url as URL

                do {
                    let unzipDirectory = try Zip.quickUnzipFile(self.path)
                    print("unzipDirectory\(unzipDirectory)")
                   
                    if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {

                        let fileURL = dir.appendingPathComponent(unzipDirectory.lastPathComponent)
                        print("fileURL\(fileURL)")
                        do {
                               let text2 = try String(contentsOf: fileURL, encoding: .utf8)
                            print(text2)
                           }
                           catch {/* error handling here */}
                }
            }
                catch {
                    print("Something went wrong")
                }

            }
        })
    } else {
        print("error")
    }
}
override func isContentValid() -> Bool {
    print("Hiii")
    // Do validation of contentText and/or NSExtensionContext attachments here
    return true
}

override func didSelectPost() {
    print("hello")
    self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
    
}

override func configurationItems() -> [Any]! {
    // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
    return []
}

in console error is:

[core] SLComposeServiceViewController got attachment coarseType 0
[core] SLComposeServiceViewController made no attachment for itemProvider conforming to public.file-url

Can anyone help please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文