share extension loading a WhatsApp Zip attachment is not working

Viewed 37

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?

0 Answers
Related