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.

startAccessingSecurityScopedResource must be called for storage access

func documentPicker(_ controller: UIDocumentPickerViewControllerdidPickDocumentsAt urls: [URL]) {

            guard controller.documentPickerMode == .openlet url = urls.first, url.startAccessingSecurityScopedResource() else { return }

            defer {

                DispatchQueue.main.async {

                    url.stopAccessingSecurityScopedResource()

                }

            }

            

            do {

                let document = try Data(contentsOf: url.absoluteURL)

              let str = saveToDocumentDirectory(url: url.absoluteURL)

                self.path = str

            }

            catch {

                print("Error " + error.localizedDescription)

            }

            

        }


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Saved Image in document directory and save path in coredata not able to fetch the image file iOS swift