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.

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

  1. 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/TestUser/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 access files directly in this way? or any other suggestions.

like 1 What’s New in File Management and Quick Look - WWDC19 - Videos - Apple Developer Your iOS app can now access files stored on external devices via USB and SMB. Understand best practices for creating a document-based app...

Answered by DTS Engineer in 794480022

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.

I don't think this will work, at least not in the general case. More specifically, there are few different issue here:

  1. I believe this path segment "asd0QUsers" is a random value generated at every mount, so the full path to the specific file will change with every mount.

  2. Until the volume is mounted, there isn't a "path" to the file and the the URL system itself can't trigger the mount.

  3. Bookmarks should be able to resolve this issue, but there is currently a bug that's prevent cross volume bookmark resolution (r.102995804), so you can't trigger the mount programmatically.

Unfortunately, all I can really recommend here is that you file a bug asking for #3 to be resolved. Please post the bug number here if/when you file.

Note that fixing the issue in #3 would also allow security scoped bookmarks to work properly, allowing you to preserve longer term access. The user could then select the file/directory once using document picker and your app could then access it again without further user interaction, which I suspect is what you'd actually prefer here.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

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.

I don't think this will work, at least not in the general case. More specifically, there are few different issue here:

  1. I believe this path segment "asd0QUsers" is a random value generated at every mount, so the full path to the specific file will change with every mount.

  2. Until the volume is mounted, there isn't a "path" to the file and the the URL system itself can't trigger the mount.

  3. Bookmarks should be able to resolve this issue, but there is currently a bug that's prevent cross volume bookmark resolution (r.102995804), so you can't trigger the mount programmatically.

Unfortunately, all I can really recommend here is that you file a bug asking for #3 to be resolved. Please post the bug number here if/when you file.

Note that fixing the issue in #3 would also allow security scoped bookmarks to work properly, allowing you to preserve longer term access. The user could then select the file/directory once using document picker and your app could then access it again without further user interaction, which I suspect is what you'd actually prefer here.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

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