File Provider

RSS for tag

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

File Provider Documentation

Pinned Posts

Posts under File Provider tag

83 Posts
Sort by:
Post not yet marked as solved
2 Replies
2.9k Views
I have created working fileprovider, that works perfectly on my local machine. Codesigned in xcode, with our company sign certificate as Developer ID Application. No provisioning profile. Also notarized result dmg. Works as expected on my local machine. But won't load on any other machine. Calling [NSFileProviderManager addDomain: ...], ends up with error: Error Domain=NSFileProviderErrorDomain Code=-2001 "The application cannot be used right now." UserInfo={NSLocalizedDescription=The application cannot be used right now.} Code=-2001 should mean, that no file provider manager extension was found in an app bundle. I have made a TestFileProvider application that is totally simplified File Provider example. This too does work only on my own machine. Relevant code from app: - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSFileProviderDomain* fileProviderDomain = [[NSFileProviderDomain alloc] initWithIdentifier:@"com.xxxxx.dwc.FileProvider" displayName:@"TestDomain"]; [NSFileProviderManager addDomain:fileProviderDomain completionHandler:^(NSError * _Nullable error) { if (error) NSLog(@"add domain: %@", error); else NSLog(@"add domain SUCCESS"); }]; } There are also these errors, that are related, but I do not understand what are they implying neither how to fix: kernel Sandbox: fileproviderd(448) deny(1) file-read-data /Applications/TestFileProvider.app fileproviderd [ERROR] PluginRecord doesn't have container url for fileproviderd [WARNING] No provider found with identifier (null) for calling bundle (null) on second attempt. I'm clueless on how to fix this. Is this related to codesign ? Or is it necessary to start fileprovider with different method call ?
Posted
by
Post not yet marked as solved
0 Replies
1.3k Views
General: DevForums tags: Files and Storage, Finder Sync, File Provider, Disk Arbitration, APFS File System Programming Guide On File System Permissions DevForums post File Provider framework Finder Sync framework App Extension Programming Guide > App Extension Types > Finder Sync Disk Arbitration Programming Guide Mass Storage Device Driver Programming Guide Device File Access Guide for Storage Devices Apple File System Guide TN1150 HFS Plus Volume Format Extended Attributes and Zip Archives File system changes introduced in iOS 17 DevForums post Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com"
Posted
by
Post not yet marked as solved
1 Replies
1.7k Views
Trying to use file importer in a swift app to upload documents into firebase Storage and getting error when running on live device but works perfectly fine on emulator. error: BackgroundSession <***...> Failed to issue sandbox extension for file file:///private/var/mobile/Library/Mobile%20Documents/comappleCloudDocs/Sample.pdf, errno = [1: Operation not permitted] UNKNOWN ERROR Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=Repository/Sample.pdf, ResponseBody=Can not finalize upload. Current size is 0. Expected final size is 2665098., bucket=bucket, data={length = 77, bytes = 0x43616e20 6e6f7420 66696e61 6c697a65 ... 32363635 3039382e }, data_content_type=text/plain; charset=utf-8, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=400} I tried separating all the logic from selectedFile.startAccessingSecurityScopedResource() all the way through the end into a function of its own using @MainActor based on another post I found around here and issue persisted.. Below is the implementation: .fileImporter( isPresented: $fileImporterIsPresented, allowedContentTypes: [.pdf], allowsMultipleSelection: false ) { result in switch result { case .success(let url): print(url) guard let selectedFile:URL = url.first else { return } guard selectedFile.startAccessingSecurityScopedResource() else { return } let firebaseRepository = Storage.storage().reference().child("Repository/Sample.pdf") let uploadTask = firebaseRepository.putFile(from: selectedFile) uploadTask.observe(.progress) { snapshot in // Upload reported progress percentComplete = 100.0 * Double(snapshot.progress!.completedUnitCount) / Double(snapshot.progress!.totalUnitCount) } uploadTask.observe(.success) { snapshot in selectedFile.stopAccessingSecurityScopedResource() uploadTask.removeAllObservers() print("SUCCESS") // Upload completed successfully } uploadTask.observe(.failure) { snapshot in if let error = snapshot.error as? NSError { switch (StorageErrorCode(rawValue: error.code)!) { case .objectNotFound: print("NOT FOUND") // File doesn't exist break case .unauthorized: print("UNAUTHORIZED") // User doesn't have permission to access file break case .cancelled: print("CANCELLED") // User canceled the upload break /* ... */ case .unknown: print("UNKNOWN ERROR \(error.description)") print("UNKNOWN ERROR \(error.localizedDescription)") print("UNKNOWN ERROR \(error.underlyingErrors)") // Unknown error occurred, inspect the server response break default: print("UNSPECIFIED ERROR") // A separate error occurred. This is a good place to retry the upload. break } } } case .failure(let error): print(error) } }
Posted
by
Post marked as solved
3 Replies
1.6k Views
The existing project of Finder Extension is doing an amazing job in other paths but when I point it to the CloudStorage path the context menu doesn't show up. And no trace of what is going wrong any where (Xcode Logs, Console log, crash log, etc.) Path Used: /Users/<User>/Library/CloudStorage/FP-SomeDomains Yes, even my first though was, it must be because of dataless file and folders. But unfortunately it not. There was no context menu presented from my Finder Extension even on real physical files and folders.
Posted
by
Post not yet marked as solved
1 Replies
1.2k Views
This seems to be a bug in the macOS FileProvider framework. Repro steps: Open a file in the File Provider domain and edit it using WPS Office Save the file in WPS and close the editor tab or WPS Office window The file in the File Provider domain shows an uploading icon, and the modifyItem(_:baseVersion:changedFields:contents:options:request:completionHandler:) callback will never be triggered, so the file won’t be uploaded, and will always shows an "uploading" icon I investigated the issue and found out that the root cause seems to be related to flock, In step 2, after saving the changes, the file is still exclusively locked by WPS Office, In the log of fileproviderd there is an error saying "itemIsFlockedCanNotPropagate", this is understandable since the file is exclusively flocked, and fileproviderd couldn’t propagate the item and trigger the modifyItem callback, What I'm struggling with is that after the file is closed, or even after the WPS Office app has been quit, the modifyItem callback still won’t be fired by the system. What’s even more interesting is that at this time if you manually invoke flock(fd, LOCK_UN) for the file, the modifyItem callback will be triggered right away. In other words, it seems to me that fileproviderd is monitoring the unlock signal of the file descriptor, if a file is flocked with flock(fd, LOCK_EX) and then closed without invoking flock(fd, LOCK_UN), fileproviderd will not able to propagate the change and the modifyItem callback will never be triggered, then FileProviderExtension or the App won’t know that file is changed, the file will always shows an “uploading” icon in Finder. I've tested this against the official FruitBusket sample, OneDrive, Box-Drive and Dropxbox, they all implemented the NSFileProviderReplicatedExtension, and all have the same issue.
Posted
by
Post marked as solved
1 Replies
877 Views
I have an app with two targets: MainApp FileProvider Extension I would like to be able to open the FileProvider CloudStorage folder in Finder from within the MainApp. So far, I've only be able to achieve that by asking user to select his Home folder via NSOpenPanel, and then persisting security-scoped bookmark data, create symbolicLink in user's home folder and then later in the app: let aliasLocationURL = try URL(resolvingBookmarkData: aliasLocationBookmarkData,                             options: .withSecurityScope,                             relativeTo: nil, bookmarkDataIsStale: &isStale) aliasLocationURL.startAccessingSecurityScopedResource() NSWorkspace.shared.open(aliasURL) aliasLocationURL.stopAccessingSecurityScopedResource() The problem is that if user does not select his Home folder via NSOpenPanel then my app gets an error message: The application “MyApp” does not have permission to open “MyApp-FileProvider.” I can get the path to CloudStorage folder via: let fileProviderFolderURL = try await NSFileProviderManager(for: domain)?.getUserVisibleURL(for: .rootContainer) and it properly states that fileProviderFolderURL is /Users/me/Library/CloudStorage/MyApp-FileProvider but whenever I try to open that path, it results in error.
Posted
by
Post not yet marked as solved
2 Replies
1.3k Views
My project has a base app which is manually signed, inside I have a FileProvider parent app and extension. When things works elegantly in Xcode debug build when I run FP App. But, when I package it, the FileProvider can't mount, fails with a generic error on parent app (Error Domain=NSFileProviderErrorDomain Code=-2001 "The application cannot be used right now." UserInfo={NSLocalizedDescription=The application cannot be used right now.} Another generic error in FileProvider demon fileproviderd(488) deny(1) file-read-data /Applications/XYZ.app/Contents/Resources/FileFP.app How to solve this?
Posted
by
Post not yet marked as solved
2 Replies
849 Views
I have a Login Item that is bundled with my .app and can run in the background. The Login Item has a File Provider extension. When a user downloads and installs a new version of the main .app, what's the correct way to handle stopping and restarting the login item and File Provider related processes to make sure they are running the latest code also?
Posted
by
Post not yet marked as solved
0 Replies
816 Views
We've written a FileProvider plugin which displays the decrypted versions of encrypted files and folders stored in Dropbox. When removing encryption from a folder, we found one file was not properly decrypted -- it remained under its encrypted name (bPw4vCA6j5LOU,QuABQSsgmC.empfs). This turned out to be the folder's .DS_Store file. For some reason, a standard C++ iteration of the FileProvider folder did not include it. Is this normal behaviour for FileProvider? For the record, the problem doesn't occur if we iterate a non-FileProvider directory on the filesystem (e.g. "/Users/orextest3/Dropbox/EMPSecureFolders/EncryptedOrexTest3/"), only if we iterate the FileProvider mounted folder ("/Users/orextest3/Library/CloudStorage/EMPSecure-EMPSecureDropbox/EMPSecureFolders/EncryptedOrexTest3/"). And in some cases, the problem doesn't occur (I suspect a Finder setting of some sort). How can I ensure that these hidden files are included in an iteration? For the record, the C++ iterator loop was implemented using boost::filesystem: for (directory_iterator itr(source); itr!=directory_iterator(); ++itr)
Posted
by
Post not yet marked as solved
2 Replies
586 Views
I need to prevent folder-creation in certain scenarios. I know I can achieve that via NSFileProviderUserInteractions but that only works when folder creation attempt is done via Finder. If however, user tries to create a folder in Terminal via mkdir folder1 then createItem callback does get called. In createItem callback I tried two options: Option 1 func createItem(basedOn itemTemplate: NSFileProviderItem, fields: NSFileProviderItemFields, contents url: URL?, options: NSFileProviderCreateItemOptions = [], request: NSFileProviderRequest, completionHandler: @escaping (NSFileProviderItem?, NSFileProviderItemFields, Bool, Error?) -> Void) -> Progress { let progress = Progress(totalUnitCount: 1) if itemTemplate.parentItemIdentifier == .rootContainer || itemTemplate.contentType == .aliasFile || itemTemplate.contentType == .symbolicLink { print("Preventing item creation in root level") let entry = Entry( id: UUID().uuidString.lowercased(), type: itemTemplate.contentType == .folder ? Entry.Kind.folder : Entry.Kind.file, filename: itemTemplate.filename, parentId: NSFileProviderItemIdentifier.trashContainer.rawValue, contentType: itemTemplate.contentType!, size: itemTemplate.documentSize as! Int, creationDate: itemTemplate.creationDate!!, modificationDate: itemTemplate.contentModificationDate as? Date, lastUsedDate: itemTemplate.lastUsedDate as? Date, fileSystemFlags: itemTemplate.fileSystemFlags?.rawValue ?? 4, version: nil, rootContainerId: nil, archived: false ) let item = FileProviderItem(entry: entry) print("Returning trashed item") completionHandler(item, [], false, nil) return progress } // other code } and indeed when creating folder via Finder (with NSFileProviderUserInteractions disabled), folder appears briefly and disappears immediatelly after that. Option 2 func createItem(basedOn itemTemplate: NSFileProviderItem, fields: NSFileProviderItemFields, contents url: URL?, options: NSFileProviderCreateItemOptions = [], request: NSFileProviderRequest, completionHandler: @escaping (NSFileProviderItem?, NSFileProviderItemFields, Bool, Error?) -> Void) -> Progress { let progress = Progress(totalUnitCount: 1) if itemTemplate.parentItemIdentifier == .rootContainer || itemTemplate.contentType == .aliasFile || itemTemplate.contentType == .symbolicLink { print("Preventing item creation at root level") let error = NSError( domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo: [ NSLocalizedDescriptionKey: "Folder creation is not allowed." ] ) completionHandler(nil, [], false, error) return progress } // other code } The problem is that with both options, when folder is created via Terminal, it stays created. Extension marks the folder with exclamation-mark and attempts to invoke createItem callback a few times before giving up. My goal is to prevent folder-creation in the first place so that when user tries to create folder in Terminal, he can get an error in respond. % mkdir folder1 error: folder creation forbidden Is that possible to achieve with FileProviderExtension?
Posted
by
Post not yet marked as solved
0 Replies
481 Views
below is the scenario... I've created a local server that'll serve me files from the system which is encrypted by a key. When i try to read the File from the server , it'll decrypt and open the file. This all is working fine in other OS systems like Windows and archLinux using Fuse and similar alternatives. Now when I'm implementing the same in macOS using File Provider. I found out that Its making a local copy which is decrypted and then opening the file (fetchContents()). This is basically breaking the whole point of the project. Is there a way to not download this file and Open directly from memory instead ? (apologies if the issue was not explained correctly or was not worth mentioning, I'm still new to macOS development)
Posted
by
Post not yet marked as solved
1 Replies
436 Views
I'm implementing FileProviderExtension on macOS (NSFileProviderReplicatedExtension) and one requirement I have to support is the support for locked files. My requirement is that writing to locked files should be forbidden. Is there a way to support that in FileProviderExtension? My approach was to report capabilities in FileProviderItem like: var capabilities: NSFileProviderItemCapabilities { if locked { return [.allowsReading, .allowsReparenting, .allowsDeleting] } return [.allowsReading, .allowsWriting, .allowsRenaming, .allowsReparenting, .allowsDeleting] } and indeed rename is forbidden (in Finder you cannot enter rename-state) but writing to file is allowed. Is there a way to prevent writing to file in macOS FileProviderExtension?
Posted
by
Post marked as solved
1 Replies
711 Views
I've been building a finder extension for managing a bunch of videos in a remote server. When I try to click on a video file that is dataless it seems to always trigger fetchContents(for:version:request:completionHandler:). I have implemented fetchPartialContents(for:version:request:minimalRange:aligningTo:options:completionHandler:) but i haven't been able to trigger this method no matter how large the size of the file is. What are the conditions that i have to meet to trigger this function so i could stream the video data in chunks ?
Posted
by
Post not yet marked as solved
0 Replies
522 Views
I need to correctly determine the mime type of keynote file and numbers file without relying on the extension. For this purpose, I am hoping to use the magic number concept and match it with the first four bytes of a file. Link for magic number understanding -> [https://www.outsystems.com/forge/component-overview/10108/validate-file-extension#:~:text=A%20magic%20number%20is%20a,types%20which%20is%20hexadecimal%20format.] Though after extensive searching online I am unable to find a unique magic number for the above files moreover first four bytes of the file is matching with the magic number of the zip file due to which I am getting the wrong extension as zip. This is the first four bytes 0x50, 0x4B, 0x3, 0x4. Is there any reliable way to find the mime type of these files without relying on an extension?
Posted
by
Post marked as solved
1 Replies
551 Views
I'm having an issue where adding new decorations to NSFileProviderDecorations doesn't make those decorations visible in the app. Here is my NSFileProviderDecorations array in plist file: <key>NSFileProviderDecorations</key> <array> <dict> <key>BadgeImageType</key> <string>com.apple.icon-decoration.badge.checkmark</string> <key>Category</key> <string>Badge</string> <key>Identifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER).iconSynced</string> <key>Label</key> <string>Synced</string> </dict> <dict> <key>BadgeImageType</key> <string>com.apple.icon-decoration.badge.warning</string> <key>Category</key> <string>Badge</string> <key>Identifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER).iconConflict</string> <key>Label</key> <string>In Conflict</string> </dict> <dict> <key>BadgeImageType</key> <string>com.apple.icon-decoration.badge.locked</string> <key>Category</key> <string>Badge</string> <key>Identifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER).iconLocked</string> <key>Label</key> <string>Locked</string> </dict> <dict> <key>BadgeImageType</key> <string>com.apple.icon-decoration.badge.warning</string> <key>Category</key> <string>Badge</string> <key>Identifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER).iconUploadFailed</string> <key>Label</key> <string>Upload failed</string> </dict> </array> The first two decorations: iconSynced and iconConflict work just fine as expected, but then I added the other two decorations: iconLocked and iconUploadFailed and I just can't get them to work. Here is an example of my decorations implementation: var decorations: [NSFileProviderItemDecorationIdentifier]? { [ entry.synced ? "iconSynced" : "", entry.inConflict ? "iconConflict" : "", entry.locked && !entry.uploadFailed ? "iconLocked" : "", entry.uploadFailed ? "iconUploadFailed" : "" ].filter { !$0.isEmpty }.map { NSFileProviderItemDecorationIdentifier(rawValue: "\(Bundle.main.bundleIdentifier!).\($0)") } } What I tried: Clear cache project and/or manually deleting Derived Data folder Various combination changes and log prints to try to figure out what's wrong Increasing Xcode project version Computer restart macOS: 12.6.5 (21G531) Does anyone have the same issue or does anyone have an idea on how to resolve this? So, my problem is that I can't get the new badge decorations added to plist file to work (to be shown in Finder when reported from decorations callback).
Posted
by
Post not yet marked as solved
1 Replies
579 Views
https://developer.apple.com/documentation/fileprovider/nsfileproviderpartialcontentfetching/3923718-fetchpartialcontents fetchPartialContents(for:version:request:minimalRange:aligningTo:options:completionHandler:) I need to use this function to fetch contents of the files partially. But it seems I'm just unable to receive any callback when i try to open the file via double click on finder. I've tried to open files of different types and sizes but still i'm defaulting back to fetchContents(for:version:request:completionHandler:) . I've been thinking if there are any specific configurations or requirements that i have to meet , so i could trigger this callback function for all the fetch Operations for files ? If No, then where am i going wrong ?
Posted
by
Post not yet marked as solved
0 Replies
620 Views
Hi, I maintain a cloud drive app which transitioned from SMB based mounting of cloud storage to File Provider. Our users on fresh installs of the app are fine, but users who updated from the SMB app are getting an error. I can see in the File Provider logs that the error is: "Failed to connect to domain socket: Connection refused". I can see in fileproviderctl listproviders that the provider does not load. Can anyone help me understand this error or what parts of the system to flush to reproduce the environment of a fresh install?
Posted
by
Post not yet marked as solved
0 Replies
503 Views
Hi there, The first time an item is materialized (via fetchContents), the contents are downloaded and we set the contentVersion (to a hash of the content) - no problems here. Once a content change is made remotely, we enumerateChanges and change the contentVersion to ”empty” (Data()). This triggers fetchContents to be called (where we fetch the new content). As soon as we call the completion handler for fetchContents though (now with a new contentVersion (a hash of the new content), we get a call immediately after to modifyContents, with the same contents that we just fetched. This call to modifyContent seems like a bug. how can I prevent it from being called by the system? Thanks for the help!
Posted
by
Post not yet marked as solved
0 Replies
376 Views
I'm working with NSFileProviderReplicatedExtension for macOS app. I want to apply default badge on files(For example, com.apple.icon-decoration.badge.warning, com.apple.icon-decoration.badge.pinned, .. etc). I am unable to see any badge when I open the folder mounted by the Extension. I've defined NSFileProviderDecorations in NSExtension as follows : <dict> <key>NSFileProviderDecorations</key> <array> <dict> <key>BadgeImageType</key> <string>com.apple.icon-decoration.pinned</string> <key>Category</key> <string>Badge</string> <key>Identifier</key> <string>$(PRODUCT_BUNDLE_IDENTIFIER).cyfile</string> <key>Label</key> <string>CydriveFile</string> </dict> </array> <key>NSExtensionFileProviderDocumentGroup</key> <string>$(TeamIdentifierPrefix)com.example.app-group</string> <key>NSExtensionFileProviderSupportsEnumeration</key> <true/> <key>NSExtensionPointIdentifier</key> <string>com.apple.fileprovider-nonui</string> <key>NSExtensionPrincipalClass</key> <string>$(PRODUCT_MODULE_NAME).FileProviderExtension</string> </dict> I have implemented the class Item that's implementing the following Protocols : NSObject, NSFileProviderItemProtocol, NSFileProviderItemDecorating and when returning decorations for that item I'm just doing this : class Item : ... { ... static let decorationPrefix = Bundle.main.bundleIdentifier! static let heartItem = NSFileProviderItemDecorationIdentifier(rawValue: "\(decorationPrefix).cyfile") var decorations: [NSFileProviderItemDecorationIdentifier]? { var decos = [NSFileProviderItemDecorationIdentifier]() decos.append(CyItem.heartItem) return decos } } As far as i can tell I've completed all the requirements for getting the badge to show up.
Posted
by