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

86 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Files and Storage Resources
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"
0
0
1.4k
Jan ’24
Is one step folder creation possible in Finder ?
I need to disallow folder renaming on my NSFileProviderReplicatedExtension extension as my foreign API system changes the asset id when a folder gets renamed and I can't retrieve or compute the new ID. For this reason I disable .allowsRenaming on folders for this volume but the Finder will still trigger the two step create "untitled folder" / rename when creating new folders. I can see that existing folders can't be renamed on the volume so the capability seems properly managed by my extension. Is there a way to prevent the creation of the "untitled folder" folder when creating new folders in Finder on a folder with renaming disabled ?
0
0
54
1d
Document Access Codes and Settings
Currently, there must be a request for access to documents with xcode, but we do not request access. Added NSDocumentDirectoryUsageDescription to info. import SwiftUI import AVFoundation import UniformTypeIdentifiers struct ContentView: View { @State private var audioPlayer: AVAudioPlayer? @State private var isPlaying = false @State private var currentFileName: String = "No file selected" @State private var showingDocumentPicker = false @State private var songList: [String] = UserDefaults.standard.stringArray(forKey: "SavedSongs") ?? [] @State private var currentSongIndex: Int = 0 var body: some View { VStack { Text(currentFileName) .font(.headline) .padding() List { ForEach(songList, id: \.self) { song in HStack { Text(song) .onTapGesture { loadAndPlaySong(named: song) } Spacer() Button(action: { removeSong(named: song) }) { Image(systemName: "trash") .foregroundColor(.red) } } } } .listStyle(PlainListStyle()) HStack(spacing: 10) { Button(action: { showingDocumentPicker = true }) { Text("Load") .font(.system(size: 12)) .frame(width: 50, height: 25) .background(Color.blue) .foregroundColor(.white) .cornerRadius(5) } .padding(.bottom, 20) } .padding() .sheet(isPresented: $showingDocumentPicker) { DocumentPicker(audioPlayer: $audioPlayer, currentFileName: $currentFileName, songList: $songList) } .onAppear { if !songList.isEmpty { loadAndPlaySong(named: songList[currentSongIndex]) } } } func playSong() { audioPlayer?.play() isPlaying = true } func pauseSong() { audioPlayer?.pause() isPlaying = false } func stopSong() { audioPlayer?.stop() audioPlayer?.currentTime = 0 isPlaying = false } func nextSong() { currentSongIndex = (currentSongIndex + 1) % songList.count loadAndPlaySong(named: songList[currentSongIndex]) } func previousSong() { currentSongIndex = (currentSongIndex - 1 + songList.count) % songList.count loadAndPlaySong(named: songList[currentSongIndex]) } func loadAndPlaySong(named songName: String) { guard let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { return } let fileURL = documentsURL.appendingPathComponent(songName) do { audioPlayer = try AVAudioPlayer(contentsOf: fileURL) audioPlayer?.prepareToPlay() currentFileName = songName playSong() } catch { print("Error loading file: \(error.localizedDescription)") } } func removeSong(named songName: String) { songList.removeAll { $0 == songName } UserDefaults.standard.set(songList, forKey: "SavedSongs") } } struct DocumentPicker: UIViewControllerRepresentable { @Binding var audioPlayer: AVAudioPlayer? @Binding var currentFileName: String @Binding var songList: [String] func makeCoordinator() -> Coordinator { return Coordinator(self) } func makeUIViewController(context: Context) -> UIDocumentPickerViewController { let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.audio]) documentPicker.delegate = context.coordinator return documentPicker } func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: Context) {} class Coordinator: NSObject, UIDocumentPickerDelegate { let parent: DocumentPicker init(_ parent: DocumentPicker) { self.parent = parent } func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { guard let url = urls.first else { return } do { if url.startAccessingSecurityScopedResource() { defer { url.stopAccessingSecurityScopedResource() } let fileName = url.lastPathComponent let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let destinationURL = documentsURL.appendingPathComponent(fileName) if FileManager.default.fileExists(atPath: destinationURL.path) { try FileManager.default.removeItem(at: destinationURL) } try FileManager.default.copyItem(at: url, to: destinationURL) parent.audioPlayer = try AVAudioPlayer(contentsOf: destinationURL) parent.audioPlayer?.prepareToPlay() parent.currentFileName = fileName if !parent.songList.contains(fileName) { parent.songList.append(fileName) UserDefaults.standard.set(parent.songList, forKey: "SavedSongs") } } else { print("I can't get file access.") } } catch { print("An error occurred while loading the file: \(error.localizedDescription)") } } func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { } } }
0
0
88
6d
NSFileProviderReplicatedExtension copy hooks?
My company has developed a desktop-Mac FileProvider extension which presents a user with shared encrypted folders; it's working well except for one issue. While we can handle moving an encrypted folder, there seems to be no way to detect that an encrypted folder has been copied or duplicated. Is there any equivalent to the Windows shell extension copy-hook handler, which can allow NSReplicatedFileProviderExtension (or some other portion of the system) to detect that a folder is being copied?
2
0
241
3w
File Provider Extension Fails to Launch but Still Appears on Side Bar
I am developing a Mac File Provider Extension. When testing installation from-scratch, The File Provider Name does appear on the side bar. However, the text '[App Name] encountered an unexpected error. Items may be out of date .....Try Again' appears at the top of the Finder window when opening the File Provider's Domain. Along with this text, there is a persistent 'Loading...' that is displayed in the middle of the Finder view. The File Provider seems to immediately get in a bad state. This does not happen at all during development. I am also noticing some logs in console that indicate some sort of issue. These 3 seem to be relevant. Any ideas or insight what could be going on? create-item(propagated:<root dbver:0 domver:<nil>>) why:itemChangedRemotely|diskImport sched:default.1717009685.233681#1717009069.3164978 error:<NSError: Cocoa 4101 "Couldn’t communicate with a helper application." Underlying={NSError: NSFileProviderInternalErrorDomain 7 "A connection to the extension “REMOVED ID” could not be made." Underlying={NSError: com.apple.extensionKit.errorDomain 2 "The operation couldn’t be completed. (com.apple.extensionKit.errorDomain error 2.)" UserInfo={(omitted)}}}}}>> → <requested:<p:root n:"i{31}e" dir child:0 m:rwxS ct:1717009068.969699 mt:1717009068.969699>> [duration 33ms44µs] Failed to create extensionProcess for extension 'REMOVED ID' error: Error Domain=com.apple.extensionKit.errorDomain Code=2 "(null)" UserInfo={NSUnderlyingError=0x7fa0ce9d28b0 {Error Domain=com.apple.extensionKit.errorDomain Code=2 "(null)" UserInfo={NSUnderlyingError=0x7fa0ce9d2ad0 {Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x7fa0ce9d33e0 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo=0x7fa0ce9d2900 (not displayed)}}}}}} Launch failed with error: Error Domain=com.apple.extensionKit.errorDomain Code=2 "(null)" UserInfo={NSUnderlyingError=0x7fa0ce9d2ad0 {Error Domain=RBSRequestErrorDomain Code=5 "Launch failed." UserInfo={NSLocalizedFailureReason=Launch failed., NSUnderlyingError=0x7fa0ce9d33e0 {Error Domain=NSPOSIXErrorDomain Code=111 "Unknown error: 111" UserInfo={NSLocalizedDescription=Launchd job spawn failed}}}}}
1
0
241
May ’24
Skip FileProvider folders without metadata
I want to traverse my local Google Drive folder to calculate the size of all the files on my drive. I'm not interested in files or directories that are not present locally. I use getattrlistbulk for traversing and it takes way too much time. I think it is because FileProvider tries to download metadata for the directories that are not yet materialised. Is there a way to skip non-materialised directories?
2
0
270
May ’24
After upgrading to macOS 14.5, the FileProvider extension is constantly restarted by the system.
When upgrading to macOS 14.5, the FileProvider extension is consistently restarted by the system. This issue was not encountered with macOS 14.0, where the FileProvider extension typically remained uninterrupted. Additionally, I observed that when adding multiple domains using the same process, only one FileProvider extension would operate in 14.0, whereas in 14.5, a separate extension runs for each domain. I haven't found any release notes mentioning this change. Is this behavior intended? I also have filled a feedback FB13810567.
1
0
248
May ’24
How to immediately cause eviction for Item upon creation?
I am developing a FileProvider extension on Mac. I was wondering what the most reliable way to evict a document as soon as possible after createItem is called for the respective item. Our use-case for this is as follows: Users can 'bulk-import' items into a FileProvider folder, and we want our application to immediately evict the item as soon as possible once the item's content is uploaded to the server. This is to save space on the user's machine. So, what is the best way to accomplish immediate eviction after item creation? I've tried calling evictItem from within the createItem function itself, but that yields many errors and can cause slowness.
3
0
348
May ’24
'iCloud' displayed when File Provider Item is marked as 'Shared'
I am developing a File Provider on Mac. I am marking some items within the domain as 'shared' via the NSFileProviderItemProtocol. However, the text 'Folder shared on iCloud by me' appears in Finder when these items are marked as shared. Is this correct? My provider has nothing to do with iCloud, which is, of course, the cloud developed by Apple. Is there a way to change this text or remove it? I've attached an image that shows the problem.
1
0
311
May ’24
Extended Attributes in File Provider Extension
I am developing a File Provider Extension on Mac. I am confused about how the extendedAttributes property works. The property never seems to be populated with any extended attributes. I've tried setting some custom extended attributes on my documents in testing, but they are never populated in the itemTemplates that are produced in the extension. The dictionary that would hold the extended attributes always is empty. I began to think that it only supported Mac-created attributes such as com.apple.quarantine. I then tried importing some files that are 'quarantined' with this appropriate extended attribute but still have not seen this data appear in my extension either. Any clarity here with what I should be expecting or what I should try would be helpful.
1
0
427
May ’24
FileProvider Testing Setup
TL:DR Can anyone provide guidance as to how to get the FileProvider testing API to work? It closes with no error and I have not been able to determine the issue despite careful attention to the documentation and signing. The Console logs seem to imply it is a Sandbox issue. Hi, Writing this as per suggested in the technical support section. I am trying to create some tests that involve controlling the calls from MacOS to the corresponding "event" functions in the FileProvider (e.g. fetchContents()) using the FileProviderExtension test API provided by Apple. I have thoroughly read the documentation (both online and within the API code) in order to get this to work. I have: Added the com.apple.developer.fileprovider.testing-mode entitlement to both my Main App as well as my FileProviderExtension Ensured my I have the correct account permissions, and provisioning profiles for my Main App as well as FileProviderExtension Added the line domain.testingModes = [.alwaysEnabled, .interactive] The issue: I found that setting the .interactive option in my domain.testingModes will result in my domain in Finder appearing to be stuck loading the root folder, and that my FileProviderExtension instance is being invalidated and closing in ~5s. It is reproducible. Is this a bug? Some things I have noticed: Attaching the debugger to the FileProviderExtension process results in no error. Additionally there is no error received when calling add(:domain). I noticed through testing that the Main App appears to be required to have the com.apple.developer.fileprovider.testing-mode entitlement in order to run a FileProviderExtension with that same entitlement. Otherwise I would receive the error: Error Domain=NSCocoaErrorDomain Code=257 "The file couldn’t be opened because you don’t have permission to view it" When trying to sign manually using a group Developer ID Application certificate as opposed to automatically with my Apple Development certificate Xcode presents the error "Main app provisioning profile" doesn't support the FileProvider Testing Mode capability." Despite this I can clearly see that is an enabled capability though the online Apple Developer portal under the Profiles section. Note that the only capabilities enabled when viewing the bundle identifiers of the Main App and FileProviderExtension are "FileProvider Testing Mode", "App Groups", and the (seemingly required) "In-App Purchases". I later realized that this was likely due to using the wrong type of provisioning profile so I generated and switched to MacOS Developer Profiles (as opposed to Distribution) and this error in XCode went away. However the above issue (FileProviderExtension instance being invalidated) persisted. If I look at the Console I see various errors from when the extension is launched till it closes: Sandbox: mdbulkimport(922) deny(1) mach-lookup com.apple.FileProvider Sandbox: hiveDiskProvider(37981) deny(1) mach-lookup com.apple.mobile.keybagd.UserManager.xpc [ERROR] Cannot query for providers. Error: NSError: Cocoa 4099 "<private>" Error from beginMonitoringProviderDomainChangesWithHandler: Error Domain=NSCocoaErrorDomain Code=4099 UserInfo={NSDebugDescription=<private>} Synchronizer coordinateReadingItemAtURL error: Error Domain=NSCocoaErrorDomain Code=3072 With the Development Provisioning Profiles I see a couple new errors: From secinitd(App Sandbox) Failed to set LS data container personality info: <private> A new error repeated a number of times from cfprefsd after trying to access some .plist files that don't appear to be on my system: Error: Couldn't open parent path due to [2: No such file or directory] Paths are: ~/Library/Containers/<extensionBundleID>/Data/Library/Preferences/ByHost/<extensionBundleID>.<ID>.plist /Library/Managed Preferences/<username>/<extensionBundleID>.plist Any help would be greatly appreciated :)
3
0
394
May ’24
When does ES_EVENT_TYPE_NOTIFY_FILE_PROVIDER_UPDATE event get raised
Description says this event will be raised when "An identifier for a process that notifies endpoint security that it is updating a file." What does this mean ? Similarly when will ES_EVENT_TYPE_NOTIFY_FILE_PROVIDER_MATERIALIZE event be raised ? Do these events get raised if any cloud provider sync app like Google Drive/Dropbox/OneDrive that usages fileprovider framework to sync the data ? In my endpoint secutiry app, I have registered for these events but i didnt receive any event *i do receive other endpoint secutiry events like ES_EVENT_TYPE_NOTIFY_CLONE etc.
0
0
337
Apr ’24
NSFileProviderManager getUserVisibleURL(for itemIdentifier: ) throws error: "The file “...” couldn’t be opened because you don’t have permission to view it."
Hello, I am encountering an error in my File Provider UI extension where, after calling NSFileProviderManager's getUserVisibleURL(for itemIdentifier: ) method, I receive an error: "The file “...” couldn’t be opened because you don’t have permission to view it." Looking at the system logs I see the following output: 2024-04-18 12:49:42.847462+0800 0x26c76 Error 0xbec93 6750 0 fileproviderd: (FileProviderDaemon) [com.apple.FileProvider:default] [ERROR] <private> is missing enumerate entitlement to lookup <private> 2024-04-18 12:49:42.847576+0800 0x26c76 Default 0xbec93 6750 0 fileproviderd: (FileProviderDaemon) [com.apple.FileProvider:default] [WARNING] No provider found with identifier <private> for calling bundle (null) on second attempt. 2024-04-18 12:49:42.847688+0800 0x26c76 Error 0xbec93 6750 0 fileproviderd: (FileProviderDaemon) [com.apple.FileProvider:default] [ERROR] Provider ID com.app.name.FileProviderExt is not allowed to provide item ID <private> to consumer ID (null) This issue only appears on my development machine with the release app bundle codesigned with the intended certificate for release. This is a machine where I have built this same application using a personal development certificate (which works fine and does not face this error). On a second Mac, which has never had this app installed, I do not face this error.
2
0
297
Apr ’24
How to show programmatically mounted network shares in Finder's sidebar
I am using NetFS's NetFSMountURLAsync api to mount SMB share in mac os app. I am able to mount the share however this share is not automatically appearing in Finder's sidebar. I tried using LSSharedFileListInsertItemURL to make the mount point available in Finder's side bar however facing crash on line, kLSSharedFileListItemBeforeFirst.takeRetainedValue() from below code snippet. let itemType: CFString = kLSSharedFileListFavoriteItems.takeRetainedValue() if let list: LSSharedFileList = LSSharedFileListCreate(nil, itemType, nil)?.takeRetainedValue() { let inPropertiesToSet: CFMutableDictionary = CFDictionaryCreateMutable(nil, 1, nil, nil) CFDictionaryAddValue(inPropertiesToSet, unsafeBitCast(kLSSharedFileListVolumesNetworkVisible, to: UnsafeRawPointer.self), unsafeBitCast(kCFBooleanTrue, to: UnsafeRawPointer.self)) let driveUrl = URL(fileURLWithPath: mountPoint) let shareUrl: CFURL = driveUrl as CFURL if let item: LSSharedFileListItem = LSSharedFileListInsertItemURL( list, kLSSharedFileListItemBeforeFirst.takeRetainedValue(), nil, iconRef, shareUrl, inPropertiesToSet, nil) { let itemRefId = LSSharedFileListItemGetID(item) let itemRefIdStr = "\(itemRefId)" userDefaults.set(itemRefIdStr, forKey: mountPoint) } } Anything wrong in above code? Also since this api is deprecated is there any alternative API to achieve this. The goal is to make the mount point available in Finder's sidebar so that user can easily access it.
2
0
362
Apr ’24
PushKit (fileProvider) calling didInvalidatePushTokenFor instead of didUpdate (credentials)
I think I've got all the keys and entitlements set up ok. I have no problem receiving normal alerts via the UNUserNotifications framework. Now I'm trying to use PushKit (for fileProvider). I have the following in my AppDelegate fileProvider = PKPushRegistry(queue: nil) fileProvider.delegate = self fileProvider.desiredPushTypes = [.fileProvider] along with the required delegate functions. I am never provided with credentials, only an immediate call to the didInvalidatePushToken delegate. Any suggestions appreciated.
0
0
310
Apr ’24
Open custom file extension in my app.
Hello. I have the following question. I have a program that creates files with its own extension and reads them. When I select a file with my extension in the Files app, it automatically opens my app. But if a file with my extension is attached to an email, when I click on my file it shows me a screen with programs to open (actually it shows my program the second time I click on the file, if I click the first time, my program is not listed) . I have a question, is it possible to make the file with my extension attached to the letter immediately open in my program without additional screens or is it not allowed. If possible, then what did I miss, based on the fact that it opens immediately from the Files program. Thank you. P.S. File how it works below: ![] [Image Edited by Moderator to Remove Personal Information]
0
0
385
Apr ’24
Locking files with FileProvider on Sonoma has different behaviour than Ventura.
We're trying to implement a file locking mechanism to prevent multiple users from editing the same file at the same time causing conflicts. Our previous implementation worked well on Ventura, but on Sonoma, even when just previewing a file in Finder in Column View, as opposed to editing, it locks. This is the same behaviour we experienced with Apple's FruitBasket sample code. There is a isFileViewerRequest flag inside the NSFileProviderRequest object provided with the NSFileProviderReplicatedExtension enumerator function. We thought this would indicate a file being edited. After further investigation, we were told that the isFileViewerRequest flag just indicates if a file is being presented, not just edited. We find the intended behaviour a bit strange, why would anyone want an icon next to a file to indicate presented? Why is the behaviour working fine on Ventura as a locking mechanism but on Sonoma it can only be considered a presented mechanism? If the intended behaviour is to indicate a file being presented, why did it change behaviour going from Ventura to Sonoma? A feature that was useful in Ventura becomes useless in Sonoma and the fix is for us to adjust to a new meaning of it. My main question is the following: Is there a recommended mechanism to determine if a file is being edited so that we can implement locking to avoid simultaneous editing? Thanks
0
1
269
Mar ’24
Trying to drag from app to finder and getting this error: Sandbox extension data required immediately for flavor public.file-url, but failed to obtain.
I'm trying to make a macOS app using SwiftUI that supports dragging arbitrary files from the app into finder. However, I'm getting this error: "Sandbox extension data required immediately for flavor public.file-url, but failed to obtain." I'm looking through the entitlements and not finding anything obvious here. I've tried various forms of NSItemProvider(): Try 1: let itemProvider = NSItemProvider(item: image.data as NSSecureCoding, typeIdentifier: image.uniformType.identifier) // Tried presenting as data itemProvider.registerDataRepresentation(for: .fileURL, visibility: .all) { completion in ... } // Tried presenting as file itemProvider.registerFileRepresentation(for: .fileURL, visibility: .all) { completion in ... } Try 2: let itemProvider1 = NSItemProvider(contentsOf: tempFileUrl, contentType: .fileURL) Tried using this form as well. In the completion handler for register*Representation(), i'm typically creating a temporary file and returning that.. (either the URL to the file or the data directly, depending on the API): let tempFileUrl = URL.temporaryDirectory.appending(path: "testfile.png") _ = tempFileUrl.startAccessingSecurityScopedResource() defer { tempFileUrl.stopAccessingSecurityScopedResource() } completion(tempFileUrl as data, nil) // option 1 completion(data, nil) // option 2 Disabling App Sandbox in the entitlements file does not work, but the error message goes away. So it seems like I have two problems: some sort of entitlement error and I must be using NSItemProvider() incorrectly. Anyone have any suggestions? I don't see to many examples out there for supporting exporting files (e.g. images) from an app into Finder. Thanks!
0
0
323
Mar ’24