I get the ApplicationSupportDirectory path like this:
let path = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)[0] as String
however for FileProvider plugin it looks like:
/var/mobile/Containers/Data/PluginKitPlugin/.../Library/Application Support/rclone.conf
instead of what I get for an Application:
/var/mobile/Containers/Data/Application/.../Library/Application Support
I need a way to get the Application's Support Directory from the FileProvider plugin.
Is that possible? If not, what other shared location I could use to access shared file between these two?
File Provider
RSS for tagAllow other apps to access the documents and directories stored and managed by your containing app using File Provider.
Posts under File Provider tag
52 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I use shared UserDefaults in my Swift FileProvider extension app suite. I share data between the containing app and the extension via User Defaults initialized with init(suiteName:).
Everything was working fine before macOS 15 (Sequoia).
I know that Sequoia changed the way the app group should be configured. My app group is know set to "$(TeamIdentifierPrefix)com.my-company.my-app".
But the containing (UI) app and the Extension read and write from and to different plist locations although the same app-group is specified for both targets in XCode.
The containing app reads and writes to "~/Library/Preferences/$(TeamIdentifierPrefix)com.my-company.my-app.plist"
The Extension reads and writes to "~/Library/Containers/com.my-company.my-app.provider/Data/Library/Preferences$(TeamIdentifierPrefix)com.my-company.my-app.plist"
Both of these locations seem completely illogical for shared UserDefaults.
I checked the value returned by FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "$(TeamIdentifierPrefix)com.my-company.my-app" in both the containing app and the Extension and the value in both of them is the same but has nothing to do with the actual paths where the data is stored as provided above. (The value is as expected - "~/Library/Group Containers/$(TeamIdentifierPrefix)com.my-company.my-app/"
P.S. Of course, $(TeamIdentifierPrefix), my-company and my-app here are placeholders for my actual values.
We are experiencing an issue where UIDocumentPickerViewController causes an uncaught exception when it is dismissed under certain conditions. The error appears as:
<NSXPCConnection: 0x301ac7660> connection from pid 2075 on anonymousListener or serviceListener: Warning: Exception caught during invocation of selector _updateRemoteBarButtonFrames:forUUID:, dropping incoming message and invalidating the connection.
Exception: DocumentManager service tried to send a message to a deallocated host proxy
DocumentManager service tried to send a message to a deallocated host proxy
(
0 CoreFoundation 0x0000000186c2a608 0013A8B1-2524-3534-B5BA-681AAF18C798 + 185864
1 libobjc.A.dylib 0x00000001841a5244 objc_exception_throw + 88
2 Foundation 0x000000018602eec0 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 8576704
3 DocumentManager 0x00000002177cf7b8 0BAEFA1B-BD6D-3472-A1B3-6E09F5DE54F2 + 96184
4 CoreFoundation 0x0000000186c2d078 0013A8B1-2524-3534-B5BA-681AAF18C798 + 196728
5 CoreFoundation 0x0000000186c2cef0 _CF_forwarding_prep_0 + 96
6 Foundation 0x00000001858b8d8c E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 753036
7 Foundation 0x00000001858b7fc8 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 749512
8 Foundation 0x00000001858b7220 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 746016
9 Foundation 0x00000001858b70d8 E2F95328-659E-3C01-97F7-52B5B3BB7AA5 + 745688
10 libxpc.dylib 0x00000002119f1a50 527F7127-9586-32C8-9D8B-2972D39EAD7A + 72272
11 libxpc.dylib 0x00000002119f35cc 527F7127-9586-32C8-9D8B-2972D39EAD7A + 79308
12 libdispatch.dylib 0x000000010160a638 _dispatch_client_callout4 + 20
13 libdispatch.dylib 0x0000000101627eac _dispatch_mach_msg_invoke + 512
14 libdispatch.dylib 0x000000010161226c _dispatch_lane_serial_drain + 352
15 libdispatch.dylib 0x0000000101628ea4 _dispatch_mach_invoke + 492
16 libdispatch.dylib 0x000000010161226c _dispatch_lane_serial_drain + 352
17 libdispatch.dylib 0x0000000101613290 _dispatch_lane_invoke + 460
18 libdispatch.dylib 0x00000001016206fc _dispatch_root_queue_drain_deferred_wlh + 328
19 libdispatch.dylib 0x000000010161fd0c _dispatch_workloop_worker_thread + 580
20 libsystem_pthread.dylib 0x0000000211998680 _pthread_wqthread + 288
21 libsystem_pthread.dylib 0x0000000211996474 start_wqthread + 8
)
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'DocumentManager service tried to send a message to a deallocated host proxy'
Steps to Reproduce
Present a UIDocumentPickerViewController inside a custom UIViewController.
Dismiss the parent UIViewController before UIDocumentPickerViewController is fully visible.
Swipe down or press the “Cancel” button in the picker.
Occasionally, the system forcefully terminates the view service, causing a crash.
Workarounds Tried (Unsuccessful)
Using UIAdaptivePresentationControllerDelegate – Not Called for UIDocumentPickerViewController.
Using viewDidDisappear to clean up – Not Called when the system terminates the picker.
Forcing dismissal before presenting a new picker
Reference to Line 42 in DOCRemoteViewController.m
From the error traceback, we see a reference to DOCRemoteViewController.m line 42, which strongly suggests that UIDocumentPickerViewController relies on a background process to manage its lifecycle. Since we don’t have access to Apple’s private code, we assume that the DocumentManager service is trying to send a message to an already deallocated instance of UIDocumentPickerViewController, leading to a crash.
One of the example wrapper implementation of us:
class DocumentPickerViewController: UIViewController, UIDocumentPickerDelegate {
private var picker: UIDocumentPickerViewController?
weak var delegate: UIDocumentPickerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
print("📄 DocumentPickerViewController - viewDidLoad() called")
setupDocumentPicker()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("📄 DocumentPickerViewController - viewDidAppear() called")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("📄 DocumentPickerViewController - viewWillAppear() called")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("📄 DocumentPickerViewController - viewWillDisappear() called")
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
print("📄 DocumentPickerViewController - viewDidDisappear() called")
}
deinit {
print("🗑 DocumentPickerViewController - deinit() called")
}
// MARK: - Setup Document Picker
private func setupDocumentPicker() {
picker = UIDocumentPickerViewController(forOpeningContentTypes: [.pdf])
picker?.delegate = self
picker?.allowsMultipleSelection = false
picker?.modalPresentationStyle = .formSheet
if let picker = picker {
present(picker, animated: false) {
print("📄 Document Picker fully presented")
}
}
}
// MARK: - UIDocumentPickerDelegate Methods
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
print("✅ User selected document(s): \(urls)")
delegate?.documentPicker?(controller, didPickDocumentsAt: urls)
dismissSelf()
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("❌ User cancelled document selection")
delegate?.documentPickerWasCancelled?(controller)
dismissSelf()
}
private func dismissSelf() {
DispatchQueue.main.async { [weak self] in
self?.dismiss(animated: true)
}
}
}
And logs for this implementation:
📄 Document Picker fully presented
📄 DocumentPickerViewController - viewDidAppear() called
❌ User cancelled document selection
The view service did terminate with error: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
📄 DocumentPickerViewController - viewDidLoad() called
📄 Document Picker fully presented
📄 DocumentPickerViewController - viewDidAppear() called
would appreciate any workarounds from the community to prevent crashes related to this issue!
Hi everyone,
I am a beginner in iOS/Swift programming. I'm trying to develop a mobile application that allows to mount a network drive in the iphone Files application via the WebDav protocol.
I saw on the internet that WebDav is no longer implemented in iOS because considered deprecated by apple.
To accomplish this task, I decided to separate responsibilities as follows:
Framework:
WebDav (responsible for communication with the WebDav server)
FileProviderExtension:
FileBridge (Responsible for bridging the gap between the WebDav Framework and the iOS Files app)
Main App
I also have an AppGroup that includes the main application and the fileproviderextension
Initially, to measure the feasibility and complexity of this task, I'd like to make a simplistic version that simply displays the files on my drive in the Files app, without necessarily being able to interact with them.
FileProviderExtension.swift:
import FileProvider
import WebDav
class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension {
private var webDavService: WebDavService?
required init(domain: NSFileProviderDomain)
{
super.init()
self.webDavService = WebDavService(baseURL: URL(string: "https://www.mydrive.com/drive")!)
}
func invalidate() {
// TODO: cleanup any resources
}
func item(for identifier: NSFileProviderItemIdentifier,
request: NSFileProviderRequest,
completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void) -> Progress {
let progress = Progress(totalUnitCount: 1)
Task {
do {
if let items = try await webDavService?.propfind(path: identifier.rawValue, depth: 1),
let item = items.first(where: { $0.itemIdentifier == identifier }) {
completionHandler(item, nil)
} else {
completionHandler(nil, NSError(domain: NSCocoaErrorDomain,
code: NSFileNoSuchFileError,
userInfo: nil))
}
} catch {
completionHandler(nil, error)
}
}
return progress
}
func fetchContents(for itemIdentifier: NSFileProviderItemIdentifier,
version requestedVersion: NSFileProviderItemVersion?,
request: NSFileProviderRequest,
completionHandler: @escaping (URL?, NSFileProviderItem?, Error?) -> Void) -> Progress {
let progress = Progress(totalUnitCount: 1)
Task {
do {
guard let service = webDavService else {
throw WebDavError.invalidResponse
}
let data = try await service.get(fileAt: itemIdentifier.rawValue)
let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent(itemIdentifier.rawValue)
try data.write(to: tempURL)
completionHandler(tempURL, nil, nil)
} catch {
completionHandler(nil, nil, error)
}
}
return progress
}
func createItem(basedOn itemTemplate: NSFileProviderItem, fields: NSFileProviderItemFields, contents url: URL?, options: NSFileProviderCreateItemOptions = [], request: NSFileProviderRequest, completionHandler: @escaping (NSFileProviderItem?, NSFileProviderItemFields, Bool, Error?) -> Void) -> Progress {
// TODO: a new item was created on disk, process the item's creation
completionHandler(itemTemplate, [], false, nil)
return Progress()
}
func modifyItem(_ item: NSFileProviderItem, baseVersion version: NSFileProviderItemVersion, changedFields: NSFileProviderItemFields, contents newContents: URL?, options: NSFileProviderModifyItemOptions = [], request: NSFileProviderRequest, completionHandler: @escaping (NSFileProviderItem?, NSFileProviderItemFields, Bool, Error?) -> Void) -> Progress {
// TODO: an item was modified on disk, process the item's modification
completionHandler(nil, [], false, NSError(domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo:[:]))
return Progress()
}
func deleteItem(identifier: NSFileProviderItemIdentifier, baseVersion version: NSFileProviderItemVersion, options: NSFileProviderDeleteItemOptions = [], request: NSFileProviderRequest, completionHandler: @escaping (Error?) -> Void) -> Progress {
// TODO: an item was deleted on disk, process the item's deletion
completionHandler(NSError(domain: NSCocoaErrorDomain, code: NSFeatureUnsupportedError, userInfo:[:]))
return Progress()
}
func enumerator(for containerItemIdentifier: NSFileProviderItemIdentifier,
request: NSFileProviderRequest) throws -> NSFileProviderEnumerator {
return FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier,
service: webDavService)
}
}
Here's the code I use to initialize my domain in the main app files:
fileprivate func registerFileProviderDomain() {
let domainIdentifier = NSFileProviderDomainIdentifier("FileProviderExtension Bundle Identifier")
let domain = NSFileProviderDomain(identifier: domainIdentifier,
displayName: "My Drive")
NSFileProviderManager.add(domain) { error in
NSFileProviderManager.add(domain) { error in
if let error = error {
print("Error cannot add domain file provider : \(error.localizedDescription)")
} else {
print("Success domain file provider added")
}
}
}
I can't get rid of the Error :
Error cannot add domain file provider : The operation couldn’t be completed. Invalid argument.
I don't know what I'm missing
Please help me understand
When running a Mac Catalyst app that uses DocumentGroup, the app fails to display the document content. The document picker works as expected, but creating a new document or opening an existing one results in an empty window. This issue occurs regardless of whether “Optimize for Mac” or “Scale iPad” is selected.
Steps to Reproduce:
1. Download the sample project provided by Apple for building a document-based app in SwiftUI.
2. Delete the macOS version of the project.
3. Add a Mac Catalyst version of the app.
4. In the Mac Catalyst settings, select “Optimize for Mac” (the bug also appears if it is “Scale iPad”).
5. Run the project on macOS.
Expected Result:
The app should correctly display the content of the document when creating or opening it.
Actual Result:
The app opens an empty window when a new document is created or an existing one is opened.
Impact:
We have received multiple 1-star reviews, and our retention has dropped by two-thirds due to this issue.
Environment: Xcode 16.1; macOS 15.1 & 15.2 (on 15.0 it works fine)
Has anyone experienced the same issue? I filed multiple reports so far.
I'm using UIDocumentPickerViewController to import document to my app from OneDrive and I want to show the OneDrive folder every time I use UIDocumentPickerViewController instead of the last folder I opened. Is it possible? Can I use pickerController.directoryURL ? And how to get folder URL of OneDrive?
class ViewController: UIViewController, DocumentDelegate {
var picker: DocumentPicker?
override func viewDidLoad() {
super.viewDidLoad()
picker = DocumentPicker(presentationController: self, delegate: self)
}
@IBAction func create_picker(_ sender: Any) {
picker?.presentDocumentPicker()
}
func didPickImage(image: UIImage?) {}
}
protocol DocumentDelegate: AnyObject {
func didPickImage(image: UIImage?)
}
class DocumentPicker: NSObject {
private var pickerController: UIDocumentPickerViewController?
private weak var presentationController: UIViewController?
private weak var delegate: DocumentDelegate?
init(presentationController: UIViewController,
delegate: DocumentDelegate) {
super.init()
self.presentationController = presentationController
self.delegate = delegate
}
func presentDocumentPicker() {
pickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.image])
if let pickerController = pickerController {
pickerController.delegate = self
pickerController.allowsMultipleSelection = false
presentationController?.present(pickerController, animated: true)
}
}
}
extension DocumentPicker: UIDocumentPickerDelegate {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let url = urls.first else { return }
print(url)
}
}
Hi,
With UIDocumentPickerViewController, there is a directoryURL property that says we can use to 'specify the starting directory for the document picker'. But it's not clear how to get the directory of a folder in iCloud Drive / Files app. How can I get the 'root' directory for a user's iCloud Drive or Dropbox folder, or the Downloads folder on their device, that I could pass to this directoryURL to make it easier for the user to pick their files?
Thanks.
We use File Provider Extension in our main app, and it is working fine.
We always call "NSFileProviderManager.add(_:completionHandler:)" function to start the extension, and "NSFileProviderManager.disconnect(reason:options:completionHandler:)" to temporarily quit the extension with the reason which will be shown in the Finder at the top of the FP domain folder.
But sometimes, when the main app calls the above functions, the following issue cases occur, and the extension does not start/stop:
The completionHandler function doesn't get called (As we noticed, we waited for 2 minutes. Then, we restarted the main app.)
One of the following errors returned: i) "The application cannot be used right now", ii) "Couldn't communicate with the helper application", iii) "No valid file provider found with identifier"
Here, the important thing is that restarting the main app once or twice clears the issue, and the extension starts.
But it is frustrating to restart the app each time we get this issue.
We want to know the following things:
Why and when do the above issues occur?
Why do they occur only sometimes, and how does the app restart clear the issue?
How do we resolve them without restarting the main app?
This has become a critical issue, so a detailed explanation would be greatly appreciated. TIA.
Topic:
App & System Services
SubTopic:
Core OS
Tags:
Files and Storage
Extensions
macOS
File Provider
iPhone 15pro iOS 18.2
Downloaded files cannot be located anywhere in Files, only by accessing Downloads in Safari. I have tried setting download folder to various locations, iCloud, Phone, Google Disk, but nothing is stored.
Has an invisible cache or temp folder been introduced? If so, it is a total fail:
When press-holding any file in Safari download, the normal file action options (Quick Look, share, store to Files, etc) are not available.
When clicking any file it opens any of several apps that has this file type associated with it, and there is no way to change the default app or disable the forced opening of an app.
I tried deleting the app opening .csv (in this case OneDrive), and another irrelevant app opened. There seems to be a hierarchy of apps-file types, and it has no logic to it.
in Chrome behaviour is as expected.
Chrome vs. Safari screen recordings: https://shorturl.at/my3Oy
Topic:
Safari & Web
SubTopic:
General
Tags:
Files and Storage
iOS
File Provider
Cloud and Local Storage
Dear Apple engineers,
Is it possible to make a fileprovider cloud volume mount path independent of the user's home folder in order to have constant path across desktop clients when files are referenced / placed by applications like Adobe Creative Cloud ?
Ideally mount or link the fileprovider cloud volume under /Volumes
Thanks,
I am using a Mac Catalyst with SwiftUI for our document-based app with DocumentGroup. The issue is that when we create a new document or open an existing one, the opened view is completely blank. It is only blank/empty when the "Optimzie for Mac" is checked. If it is "Scaled t oMatch iPad", then it works well.
Xcode 16.1
macOS 15.1
struct DocumentGroupTestApp: App {
var body: some Scene {
DocumentGroup(newDocument: WritingAppDocument()) { file in
TestView() // it is empty when it gets opened. It does not work if the option "Optimize for Mac" is checked. If it is scale iPad, then it works.
}
}
}
struct TestView: View {
var body: some View {
Text("Hello, World!")
}
}
Hello,
I'm seeing a strange error on another user's device where the SwiftUI file importer doesn't do anything at all. When selecting multiple files and hitting "open", the importer just freezes. Here's a video showing the problem: https://streamable.com/u5grgy
I'm unable to replicate on my own device, so I'm not sure what could be going on. I have startAccessingSecurityScopedResource and stopAccessingSecurityResource everywhere I access a file from fileImporter as well.