swift – Is there any approach to write/copy/transfer recordsdata from iOS utility to OTG usb related to iOS gadget?

Spread the love


I wish to copy file that downloaded from server and saved in doc listing to OTG usb gadget related to my iPhone, I can get path of usb gadget however after I wish 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 title of the usb gadget).

I used UIDocumentPickerViewController to get path of the usb.

I’ve tried to put in writing 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 = strive Information(contentsOf: fileURL!).base64EncodedData()
            strive information.write(to: selectedURL, choices: .noFileProtection)
            print("Information written efficiently!")
            do {
                strive 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()
                }
            }
            strive FileManager.default.copyItem(at: fileURL!, to: selectedURL)
            print("Information written efficiently!")
            do {
                strive 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 utility?

Leave a Reply

Your email address will not be published. Required fields are marked *