File Provider

RSS for tag

Allow other apps to access the documents and directories stored and managed by your containing app using File Provider.

Posts under File Provider tag

69 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Any specific event that can be monitored for tracking file upload via fileproviderd/extension?
Hi Team, I am trying to explore ESF events specifically generated by cloudsync extensions built on File Provider framework. Brief: I have high-level understanding of how various cloud vendors have provided their extensions to sync data from cloud/remote storage to local filesystem (and vice-versa). e.g.iCloudDriveFileProvider (icloud), DFSFileProviderExtension (google drive). There are 2 ESF AUTH events for file provider I can see namely: ES_EVENT_TYPE_AUTH_FILE_PROVIDER_MATERIALIZE , ES_EVENT_TYPE_AUTH_FILE_PROVIDER_UPDATE. and respectively their NOTIFY events. Observation: Observed that these events are generally triggered by fileproviderd process during download scenario i.e. syncing files from cloud/remote storage to local file system. i.e. 'materialize' for new file creation and 'update' for updating existing file. Question/Problem: Is there a correct way to find which cloud provider has triggered this download event? i.e. weather it is iCloudDriveFileProvider or DFSFileProviderExtension (there is this instigator field in Materialize event struct, but could not find similar for Update event. Are there similar ESF events for upload scenario? (I have fair understanding of how file-to-upload is copied to temp location and then uploaded by respective extensions to remote storage, but then they work with original files clone created in their temp location, so the AUTH events generated by this extension will wont reveal the original file name even if I am able to get the Fileprovider name) To Summarize: Basically I am looking for ESF event that will be triggered during upload scenario that can also let me know original file name as well the cloudprovider extension process name. As of now 'fileproviderd' process name is obtained from filesystem ESF events like AUTH_OPEN etc.
4
0
708
Sep ’24
Are TCC permissions inherited by bundled extensions?
Hello, If a user allows access to, for example, Removable Volumes (TCC permission) to the main app, does these permissions will be inherited by a bundled Finder Extension from the main app? More specific, I have an app that bundles a Finder Extension and both the main app and the bundled extension need access to Removable Volumes. Only the main app can request it, since the main app is the only that can prompt the user. If the user allows, will the bundled extension also receive the permissions? If not, is there any workaround? Regards.
1
0
554
Sep ’24
Access of removable volumes from file provider on macOS Sequoia
Hello, I developed a file provider extension that can access files from multiple locations. With the new macOS Sequoia I cannot access files from volumes, here is the error from Console: Refusing TCCAccessRequest for service kTCCServiceSystemPolicyRemovableVolumes from extension Sub:{com.app.ext}Resp:{TCCDProcess: identifier=com.app.ext-Driver, pid=26706, auid=501, euid=501, binary_path.... Driver}, extension point disallows prompting I added "Privacy - Removable Volumes Usage Description" values for both the main app and extension Info.plist, I click Allow on the alert, but still I receive this error message. Any solution? Thank you.
3
0
792
Sep ’24
[ERROR] Could not create a bookmark: NSError: Cocoa 4097 "connection to service named com.apple.FileProvider" when using PhotosPicker
Hi I am using PhotosPicker and SwiftData with iOS17.0. I released my own app using codes of two above. No problem came up right until I upgraded my iphone to iOS 18.0 17th of September 24. A single post pokes the similar problem. SwiftData and PhotosPikcer. He or She said it was about SwiftData Model Insert something. But, I was able to use other methods that use SwiftData, so insert Model setup isn't my problem. But when tapping a photo to get a photo from PhotosPicker makes the ui goes down, and navigate back. Weird. iIt doesnt crash but when I tap a photo, the debug message [ERROR] Could not create a bookmark: NSError: Cocoa 4097 "connection to service named com.apple.FileProvider" comes up and the view navigates back. The selecting a photo itself doesnt include any SwiftData related methods, it only does loadTransferable thing and shows the photo on the screen. I cannot understand it. it only happened when I upgraded to iOS 18.0. AND Then i debugged the prob with Xcode 16.0 nothing but the unexpected message appears and not many posts are up here or google. Can you help me? Things I tried: Check any use of the PhotosPickerItem anywhere else. -> No where. Use try await loadTransferable Changed the form of initiating PhotosPikcer View Debugging every line -> Nothing appeared. PhotosPicker(selection: $currentImage, matching: .images, photoLibrary: .shared()) { Text("") } .frame(height: 360) .photosPickerStyle(.inline) .photosPickerAccessoryVisibility(.hidden, edges: .bottom) .photosPickerDisabledCapabilities(.selectionActions) .onChange(of: currentImage) { _, newImage in // SomeLogic } .ignoresSafeArea(edges: .bottom) .transition(.move(edge: .bottom).combined(with: .opacity))
8
4
2.1k
Oct ’24
obtaining file creation & modified time & size failing 5-10% of time within .onOpenURL when file shared with app
When users share a file with my app I am having trouble 5-10% of the time obtaining the file meta data, specifically creation and modified time and size. Using SwiftUI with the code below.. .onOpenURL { url in var fileSize: Int64 = 0 var creationTime: Date = Date(timeIntervalSince1970: 0) var modificationTime: Date = Date(timeIntervalSince1970: 0) do { let fileAttributes = try FileManager.default.attributesOfItem(atPath: url.path) fileSize = fileAttributes[FileAttributeKey.size] as? Int64 ?? 0 creationTime = fileAttributes[FileAttributeKey.creationDate] as? Date ?? Date(timeIntervalSince1970: 0) modificationTime = fileAttributes[FileAttributeKey.modificationDate] as? Date ?? Date(timeIntervalSince1970: 0) <SNIPPED CODE no other tries though and not involving above variables> } catch { // quite confident I am ending up here because variables after the above code aren’t being set and there are no other try blocks, // so FileManager.default.attributesOfItem(atPath: url.path) must be throwing…. } <SNIPPED CODE> To attempt to resolve this, I added in a 0.5 second wait cycle if creationTime == 0 and modificationTime == 0 , so if obtaining both metadata fails, wait 0.5 seconds and try again, try this a max of 3 times and then give up. I don’t know how often I am entering this code (didn’t instrument the app for it), but am still getting times when metadata comes back blank which means this code wasn’t successful after 3 tries. I assume the file would only become visible and sharable with my app after it has completed being written by the original app/process. Perhaps it hasn’t finalized yet? Is there a way to detect this so I can tell the user in my share screen to wait and try again? I am assuming that the file has finished writing though since when I read the data from the file contents, it’s good data and complete even when metadata failed. I will be instrumenting the above code in my next app version, just hoping to fix it right now since users are emailing saying my app is broken. Thanks!
3
0
616
Sep ’24
How can I read a dataless file from within the same or another FileProvider extension?
How can I read a dataless file from within the same or another FileProvider extension? When I pass the visible URL to AVAsset from AVFoundation, it throws the following error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x15b01b1e0 {Error Domain=NSPOSIXErrorDomain Code=11 "Resource deadlock avoided"}, NSLocalizedFailureReason=An unknown error occurred (11), AVErrorFailedDependenciesKey=( "assetProperty_Tracks" ), NSURL=file:///Users/<<username>>/Library/CloudStorage/<<file-path>>, NSLocalizedDescription=The operation could not be completed} The code snippet works fine if executed as a separate Swift process. I'm using AVAsset with AVAssetExportSession to export a subset of the file being read. So I can't use NSFileProviderManager.requestDownloadForItem(withIdentifier:, requestedRange:) because I don't know the offset range required by the AVFoundation library.
1
0
560
Sep ’24
How can I access the download status of an NSFileProviderItem from the File Provider extension?
When capturing materialized information from materializedItemsDidChange in NSFileProviderReplicatedExtension, the isDownloaded property of NSFileProviderItem is not set during the call to enumerate items (NSFileProviderEnumerationObserver:enumerateItems(for:startingAt:)). Both the IsDownloaded and isMostRecentVersionDownloaded properties are returning false, even though the item is fully materialized How to capture this information from file provider extension ? Any help would be greatly appreciated. Thanks!
2
0
794
Sep ’24
Force Item Download in File Provider
I've file provider implementation where, in some cases, we must force download items, so they get materialized in local cache. I've used requestdownloadforitem based on following documentation https://developer.apple.com/documentation/fileprovider/nsfileprovidermanager/requestdownloadforitem(withidentifier:requestedrange:) I'm calling this within Extension code, but this does not trigger the download. How can I force file provider to download a file? cheers,
1
0
464
Aug ’24
File Provider Delete Enumerated Folders
I am developing a file provider extension on Mac. I noticed when attempting to delete an enumerated folder with didDeleteItems, passing only the top-level folder's ID is not enough to delete the item. It seems we need to pass all items underneath as well to this function for the folder to be removed. Is there a way around this? The way our application is designed makes it challenging to do this and we would prefer being able to remove the folder by utilizing the item ID only. If not, how could we obtain the particular items underneath that should be passed in to the function?
2
0
513
Aug ’24
How to disable Finder "Move to Bin" action for non materialised files
In the context of a NSFileProviderReplicatedExtension I would like to only see the "Move to Bin" Finder action when files have been materlialised ( isDownloaded fileprovider attribute ) I thought it might be possible to get the isDownloaded attribute in my NSFileProviderItemProtocol class capabilities method but that doesn't seem to be the case. Possible ?
1
0
482
Aug ’24
FileProvider extensions Mac Catalyst availability and workarounds
A have the application with iOS and Mac Catalyst versions and I need to make a cloud client for the app's documents. FileProvider would be the great choice for this feature, but I can't believe it doesn't support Mac Catalyst. At this moment I'm almost certain that NSFileProviderReplicatedExtension does not support Mac catalyst officially. And if it so, It would be great to hear the exact status and future plans if any. Unofficially, I managed to run it. I switched the extension's target Supported Destination from Mac Catalyst to Mac and it started to compile. This move seems legit to me. But domain also had to be created, and this part was a way trickier. I've added new bundle to host app(iOS and catalyst), but with supported platform - macOS in build settings. There I created an NSObject subclass DomainManager which calls NSFileProviderManager's addDomain method in its createDomainIfNeeded(), which is also exposed in public extension to NSObject - a kind of "informal protocol" The catalyst app creates bundle by name and loads principal class (DomainManager), but as NSObject reference, and then calls createDomainIfNeeded() method on it. The location defined by domain appears in Finder sidebar, and the dataless item "a file" appears in this location, as defined by stub implementation in the extension enumerator method. This means file system instantiated the extension instance under Mac catalyst and called the protocol method on it. I.e. it seem to work. But the question is whether this solution is stable and legit for the App Store distribution. Or is it pandora box with unforeseeable consequences for user data? Thanks in advance.
3
1
660
Aug ’24
Partial Download Support for macOS NSFileProvider Implementation
I've implemented a file provider for macos, and it works well. Now I'm trying to add partial download support in my implementation. however, it doesn't seem to work. As per documentation, I've implemented protocol NSFileProviderPartialContentFetching and its method func fetchPartialContents(for: NSFileProviderItemIdentifier, version: NSFileProviderItemVersion, request: NSFileProviderRequest, minimalRange: NSRange, aligningTo: Int, options: NSFileProviderFetchContentsOptions, completionHandler: (URL?, NSFileProviderItem?, NSRange, NSFileProviderMaterializationFlags, (any Error)?) -> Void) -> Progress Now, I'm testing my implementation, and I open a movie from my File Provider using VLC. I see that fetchPartialContents get a hit. I download requested range, and return it through completionHandler. However VLC gives a read error. here is my implementation of fetchPartialContents: private func align(range: NSRange, to alignment: Int) -> NSRange { let start = range.location - (range.location % alignment) let end = range.location + range.length let alignedEnd = ((end + alignment - 1) / alignment) * alignment let alignedLength = alignedEnd - start return NSRange(location: start, length: alignedLength) } unc fetchPartialContents(for itemIdentifier: NSFileProviderItemIdentifier, version requestedVersion: NSFileProviderItemVersion, request: NSFileProviderRequest, minimalRange requestedRange: NSRange, aligningTo alignment: Int, options: NSFileProviderFetchContentsOptions = [], completionHandler: @escaping (URL?, NSFileProviderItem?, NSRange, NSFileProviderMaterializationFlags, (any Error)?) -> Void) -> Progress { let alignedRange = align(range: requestedRange, to: alignment) let progress = Progress(totalUnitCount: 100) let data = downloadData(for: alignedRange) progress.completedUnitCount = 100; tempFileHandle = try FileHandle(forWritingTo: tempFileURL) tempFileHandle.seek(toFileOffset: UInt64(alignedRange.location)) tempFileHandle.write(data!) tempFileHandle.closeFile() let item = FileProviderItem(identifier: itemIdentifier,) completionHandler(tempFileURL, item, alignedRange, [], nil) } catch { completionHandler(nil, nil, alignedRange, [], error) } } I beleive I'm doing everhting correctly & as per documentation, but certainly there is something is wrong. Can someone help me about it? cheers,
2
0
548
Aug ’24
iOS file provider extension services
Using NSFileManager's getFileProviderServicesForItemAtURL method, I can list services made available by a file provider for a given item from an app unrelated to the file provider, obtain a handle to the proxy object and cast that object to the target protocol. However, attempts to invoke the protocol yield: "The connection to service named com.apple.mobile.usermanagerd.xpc was invalidated: failed at lookup with error 159 - Sandbox restriction." The documentation for the supportedServiceSourcesForItemIdentifier method implemented by the extension suggests only the app containing the extension can exercise the service but the documentation for getFileProviderServicesForItemAtURL does not. Should I be able to access a service from a file provider extension from an unrelated app? If so, how can the sandbox restriction be addressed?
2
0
815
Aug ’24
Getting "No valid file provider found with identifier"
I am currently developing an app based on a file provider extension and intermittently encounter the error: No valid file provider found with identifier. Usually, I can mount (addDomain) successfully after building the app, but occasionally this error appears and then disappears after 10-15 minutes I see these errors from log stream: 2024-07-28 01:01:46.644401+0530 0x1abf0 Default 0x0 6654 0 fileproviderd: (FileProviderDaemon) [com.apple.FileProvider:default] [WARNING] No provider found with identifier (null) for calling bundle <private> on second attempt. 2024-07-28 01:01:47.099043+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] Cannot query for providers. Error: NSError: Cocoa 4099 "<private>" 2024-07-28 01:01:47.099203+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] received an error when listing providers, attempting again: Error Domain=NSCocoaErrorDomain Code=4099 UserInfo={NSDebugDescription=<private>} (count: 3) 2024-07-28 01:01:47.100009+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] Cannot query for providers. Error: NSError: Cocoa 4099 "<private>" 2024-07-28 01:01:47.100141+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] received an error when listing providers, attempting again: Error Domain=NSCocoaErrorDomain Code=4099 UserInfo={NSDebugDescription=<private>} (count: 2) 2024-07-28 01:01:47.100898+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] Cannot query for providers. Error: NSError: Cocoa 4099 "<private>" 2024-07-28 01:01:47.101112+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] received an error when listing providers, attempting again: Error Domain=NSCocoaErrorDomain Code=4099 UserInfo={NSDebugDescription=<private>} (count: 1) 2024-07-28 01:01:47.101951+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] Cannot query for providers. Error: NSError: Cocoa 4099 "<private>" 2024-07-28 01:01:47.102510+0530 0x1aac7 Error 0x0 6926 0 mdbulkimport: (FileProvider) [com.apple.FileProvider:default] [ERROR] can't get the list of providers: NSError: Cocoa 4099 "<private>" When the issue occurs, the following command does not list my provider: fileproviderctl dump Any help would be greatly appreciated. Thanks!
2
1
771
Jul ’24
How to populate the Finder comments field from NSFileProviderItemProtocol
In NSFileProviderItemProtocol I am able to use the extendedAttributes property call to add my custom extended attributes to my NSFileProviderReplicatedExtension extension files. Given that the Finder uses com.apple.metadata:kMDItemFinderComment extended attribute for file comments I thought it would be possible to populate my files with useful comments provided by the third part API. Unfortunately I seems to be unable to do so as if com.apple.metadata.... fields were inaccessible from the FP extension. Is there any way to achieve this ?
1
0
459
Aug ’24
ContentsOfDirectory for FileProvider URLs
I'm developing an iOS app. Through a .fileImporter I get access to a directory URL which might be provided by an external service like Dropbox (using a FileProvider). As the user picked the URL I have full access to it. I want to get the contents of the directory: FileManager.default.contentsOfDirectory( at: url, includingPropertiesForKeys: keys, options: [.skipsHiddenFiles] ) Unfortunately I only get whatever files the system is currently aware of, which in case of external providers is often not much. If the user opens the Apple Files app and navigates to the folder then the system gets the content from the external provider and back in my app contentsOfDirectory would show everything. What can I do to get a list of the URLs? Can I somehow trigger the system to update from the external provider? Or is there another way of handling this situation?
2
0
486
Jul ’24
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/ 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 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.
1
0
808
Jul ’24