London Escorts sunderland escorts 1v1.lol unblocked yohoho 76 https://www.symbaloo.com/mix/yohoho?lang=EN yohoho https://www.symbaloo.com/mix/agariounblockedpvp https://yohoho-io.app/ https://www.symbaloo.com/mix/agariounblockedschool1?lang=EN
-7.3 C
New York
Sunday, February 2, 2025

swift – ERROR: UIDocumentInteractionController has no delegate. when making an attempt to open a PDF in my Capacitor iOS utility


I’ve a Ionic Angular utility which makes use of the capacitor bridge to work together with iOS native.

I’ve created a customized plugin which sends file paths to the native facet in order that I can merge the information after which open the brand new file.

At the moment nonetheless the code runs up till I attempt to open the file. I’m pretty new to Swift and iOS programming so any assist can be appreciated.

Right here is the code:

import Capacitor
import PDFKit


@objc(GeneratePdfPlugin)
public class GeneratePdfPlugin: CAPPlugin, UIDocumentInteractionControllerDelegate {
    @objc func generatePdfNative(_ name: CAPPluginCall) {
                
        let worth = name.getString("worth") ?? ""
        
        if let jsonData = worth.knowledge(utilizing: .utf8),
            let jsonArray = strive? JSONSerialization.jsonObject(with: jsonData, choices: []) as? [String] {
        
            if let outputURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("merged.pdf") {
                var inputURLs: [URL] = []

            
                
                for fullPath in jsonArray {
                    print(fullPath)
                    inputURLs.append(URL(fileURLWithPath: fullPath));
                }

                mergePDFs(inputURLs: inputURLs, outputURL: outputURL)
                
                                
                let fileManager = FileManager.default
                guard let outputDirectory = strive? fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false) else {
                    name.reject("Did not entry the paperwork listing")
                    return
                }

                let outputURL = outputDirectory.appendingPathComponent("merged.pdf")
                
                DispatchQueue.predominant.async {
                    let documentController = UIDocumentInteractionController(url: outputURL)
                    documentController.delegate = self
                    documentController.presentPreview(animated: true)
                }

            } else {
                print("Couldn't create the output file URL.")
            }
            
            
        } else {
            print("Invalid JSON format")
        }
    }
    
    func mergePDFs(inputURLs: [URL], outputURL: URL) {
        let pdfDocument = PDFDocument()

        for inputURL in inputURLs {
            if let doc = PDFDocument(url: inputURL) {
                for pageIndex in 0 ..< doc.pageCount {
                    if let web page = doc.web page(at: pageIndex) {
                        pdfDocument.insert(web page, at: pdfDocument.pageCount)
                    }
                }
            }
        }

        pdfDocument.write(to: outputURL)
    }
}


right here is the error:

ERROR: UIDocumentInteractionController delegate should implement documentInteractionControllerViewControllerForPreview: to permit preview

Cheers

Related Articles

Social Media Auto Publish Powered By : XYZScripts.com