1. Set up plist info file


2. Right code
2.1 implement UIDocumentPickerDelegate:


class NewTermConditionSettingViewController: UIViewController, UIDocumentPickerDelegate {

2.2 Make 2 functions:

// This func will be called when a button import tapped


func ImportFiles(){
        let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypePDF as String], in: .import)
        documentPicker.delegate = self
        documentPicker.allowsMultipleSelection = false
        present(documentPicker, animated: true, completion: nil)
    }



// MARK: - UIDocumentPickerDelegate
    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        print("documentPicker")
        guard let selectedFile = urls.first else {
            return
        }
        let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let sandboxFileURL = dir.appendingPathComponent(Constants().TermConditionFileName)
        if FileManager.default.fileExists(atPath: sandboxFileURL.path){
            do{
                try? FileManager.default.removeItem(at: sandboxFileURL)
                print("The old File deleted ")
            }catch{
                print("error: \(error)")
            }
            
        }
        do{
                try FileManager.default.copyItem(at: selectedFile, to: sandboxFileURL)
                print("File copied")
        }catch{
                print("error: \(error)")
        }
        
    }

Comments

Popular posts from this blog

return value to controller caller

Apple Push Notification Service APNS

Delivery In House iOS app