HomeiOS Developmentswift - Is there any approach to write/copy/transfer information from iOS software...

swift – Is there any approach to write/copy/transfer information from iOS software to OTG usb linked to iOS machine?


I need to copy file that downloaded from server and saved in doc listing to OTG usb machine linked to my iPhone, I can get path of usb machine however once I need to copy, transfer or write file to usb I get errors The file “STORAGE” couldn’t be saved within the folder “com.apple.filesystems.userfsd” and Permission denied (“Storage” is identify of the usb machine).

I used UIDocumentPickerViewController to get path of the usb.

I’ve tried to jot down information:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard let selectedURL = urls.first else { return }
        do {
            let shouldStopAccessing = selectedURL.startAccessingSecurityScopedResource()
            defer {
                if shouldStopAccessing {
                    selectedURL.stopAccessingSecurityScopedResource()
                }
            }
            let information = attempt Information(contentsOf: fileURL!).base64EncodedData()
            attempt information.write(to: selectedURL, choices: .noFileProtection)
            print("Information written efficiently!")
            do {
                attempt FileManager.default.removeItem(atPath: fileURL!.path)
            } catch {
                print("Couldn't delete file, most likely read-only filesystem")
            }
        } catch {
            print("Error writing information: (error.localizedDescription)")
        }
    }

even copy file with FileManager:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        guard let selectedURL = urls.first else { return }
        do {
            let shouldStopAccessing = selectedURL.startAccessingSecurityScopedResource()
            defer {
                if shouldStopAccessing {
                    selectedURL.stopAccessingSecurityScopedResource()
                }
            }
            attempt FileManager.default.copyItem(at: fileURL!, to: selectedURL)
            print("Information written efficiently!")
            do {
                attempt FileManager.default.removeItem(atPath: fileURL!.path)
            } catch {
                print("Couldn't delete file, most likely read-only filesystem")
            }
        } catch {
            print("Error writing information: (error.localizedDescription)")
        }
    }

However none of those strategies labored.

Is there any approach to copy the file to the USB from iOS software?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments