Issue while accessing file from another PC on local network using document picker with SMB.

We are trying to access and copy some files [e.g., video file] from another PC on local network using SMB protocol. We found some third party libraries like AMSMB2 for this.  But we want to try to use Apple inbuilt features like File management mentioned in - https://developer.apple.com/videos/play/wwdc2019/719/

  1. We could able to select file from SMB server using document picker in app manually. Also we got its url in debug which gets generated under "Shared" section in files app.

  2. The URL I get from document picker is -> /private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/asd0QUsers/testuser/iOS/SMB_ShareFolder

  3. Now we want to avoid manual selection of file to user.We want directly open "/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/asd0QUsers/testuser/iOS/SMB_ShareFolder" path as soon as document picker opens. So that user can directly select file. But it is not working. It opens normal files app and all folders.

  • Getting below error - 

Access Shared URL directly using documentPicker "Error - CFURLResourceIsReachable failed because it was passed a URL which has no scheme"

Sharing the code which I tried to open this shared folder directly : 

let url = URL (string: "/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/asd0QUsers/Pranjali/iOS/SMB_ShareFolder")
 let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.folder])
    documentPicker.delegate = self
    documentPicker.allowsMultipleSelection = false
    documentPicker.modalPresentationStyle = .custom
    documentPicker.definesPresentationContext = true
    documentPicker.directoryURL = url!  
    documentPicker.transitioningDelegate = customTransitioningDelegate
   present(documentPicker, animated: true, completion: nil)
  • I get error in console - CFURLResourceIsReachable failed because it was passed a URL which has no scheme 2024-07-05 17:49:38.501059+0530 VideoImportPOC[1327:336989] [DocumentManager] revealDocumentAtURL encountered an error: Error Domain=NSCocoaErrorDomain Code=262 "The file couldn’t be opened because the specified URL type isn’t supported."

Can you please provide inputs if it is possible to access files directly in this way? or any other suggestions.

Answered by DTS Engineer in 794378022

The immediately cause of your error is this:

let url = URL(string: "/private/…")

When creating a URL from file system path, use URL.init(fileURLWithPath:).

However, I doubt that’ll resolve your main issue. While hard coding this path might work during testing, it won’t to be reliable in the long term.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The immediately cause of your error is this:

let url = URL(string: "/private/…")

When creating a URL from file system path, use URL.init(fileURLWithPath:).

However, I doubt that’ll resolve your main issue. While hard coding this path might work during testing, it won’t to be reliable in the long term.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Issue while accessing file from another PC on local network using document picker with SMB.
 
 
Q