Document picker pdf file upload to server working in simulator but not working on real device iOS swift
Solution:
Because it had security issues for accessing the storage in real device.So follow the below code to copy the data or file to the document directory or your local variable after that upload it to the server.Then no issue will be appear.
startAccessingSecurityScop
func documentPicker(_ controller: UIDocumentPickerViewController
guard controller.documentPickerMode == .open, let url = urls.first, url.startAccessingSecurityScop
defer {
DispatchQueue.main.async {
url.stopAccessingSecurityScope
}
}
do {
let document = try Data(contentsOf: url.absoluteURL)
let str = saveToDocumentDirectory(url: url.absoluteURL)
self.path = str
}
catch {
print("Error " + error.localizedDescription)
}
}
Comments
Post a Comment