Files and Storage

RSS for tag

Ask questions about file systems and block storage.

Posts under Files and Storage tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

How to clean up UNNotificationAttachments?
I use a UNNotificationServiceExtension to download an image into temporaryDirectory that is attached as an UNNotificationAttachment to the notification. FileManager.default.temporaryDirectory .appendingPathComponent(UUID(). .appendingPathExtension(image.ext) data.write(to: fileUrl) let attachment = ... attachments.append(attachment) The documentation for UNNotificationAttachment say I am responsible to manage the storage space for such attachments: The system limits the amount of storage space allocated for attachments for each app. To delete attachments, use the methods of the UNUserNotificationCenter class to remove the notification requests that contain those attachments. https://developer.apple.com/documentation/usernotifications/unnotificationattachment Do I need to check in my AppDelegate if there are any notifications that are no longer displayed and remove their files? If so, how how to get a list of notifications that are no longer displayed?
0
0
394
Oct ’23
The correct way to write files to /Library
Hello - I’m creating an app that needs to copy ColorSync profiles to the /Library/ColorSync/Profiles directory on macOS and was wondering what is the correct / sanctioned way to write to the /Library directory is? The app won’t be in the App Store. The app needs to run on Big Sur through Sonoma. I spent some time working with ColorSyncProfileInstall() but that seems to want to ask the user permission every single time the function is called - and this app can install up to 25 profiles at a time. (There are actually hundreds of profiles that can be chosen that will come from a server). I’m currently looking at using SMJobBless but that sure seems like using an atomic bomb to swat a mosquito. Any thoughts if SMJobBless is the right way to go? (SMAppService for 13 and on). Thanks!
1
0
683
Oct ’23
FileProvider's eviction is failing with resource busy error though no file is open
I have applied content policy as "downloadEagerlyAndKeepDownloaded" on the folder which i want to materialise (want to implement windows similar feature Always keep on this device feature in mac os in FileProvider). For root item the policy is downloadLazily and for rest of the item it is inherited. The issue i am facing is, while dematerialising the folder, the file provider'e evictItem api is continuously failing with resource busy error though there is no file from that folder in an open state. And it keeps giving the same error and unable to dematerialise that folder.
1
0
515
Oct ’23
Is there any API for Full Disk Access in MacOS?
From this post, it is clear there was API as such to know if the FDA was granted or not. https://developer.apple.com/forums/thread/114452 But this post is 4 years old. I tried to find one that would ease my work, but to my surprise we are still there. So how an Application decide to know if FDA given then proceed, otherwise show a custom message/screen etc? Apple should expose and API in Terminal, Plist, Cocoa.
1
0
405
Oct ’23
How do we delete our apps "Data & Documents" when developing on Unreal Engine for iOS?
We published an app for iOS which accidentally stores a ton of photos in "Data & Documents". The app is live on the App Store, but currently the only way for a user to delete this bloat is to uninstall and re-install the app. Updating does not delete it. We fixed the bug, and put in a notice on the App Store page, but we'd rather take care of this on our end. The app was developed using Unreal Engine 5.1.1. The bloat is caused by Apple ARKit having had the should_write_camera_image_per_frame turned on (see https://docs.unrealengine.com/5.0/en-US/PythonAPI/class/AppleARKitSettings.html). The images are saved to Container/Documents/CameraImages. How can we make it so the next version we push to App Store will delete the contents of this folder upon launch?
0
0
393
Oct ’23
fileManager.copyItem with overwrite?
I'm would like to make a copy of a folder with files and folders in it before I do anything to them. When I naively fileManager.copyItem() I get errors about .DS_Store files already existing (I think the Finder might be creating them before the copy gets to it). The destination directory is empty at the start of the process. Is there any way to tell copyItem to overwrite? Is replaceItemAt() a way to do this, with backupItemName set to the original name and withoutDeletingBackupItem set in options? That seems so convoluted. Is there a better way?
5
0
957
Oct ’23
iOS 17 Airdropped file not opening in our app and instead opening in files app
Our application is configured to handle a custom file type with the extension .ptw. Until the release of iOS 17, when we used Airdrop to send a .ptw file, it would seamlessly open directly in our app on the receiving device. However, since iOS 17, we've noticed a change in behavior where the .ptw file is now being automatically saved to the Files app. To access it in our app, we must manually tap the share button and select our app from the sharing menu. I'm curious to know if others have experienced this change as well, and whether this is the expected behavior in iOS 17 or We are missing some configurations to regain the previous behaviour. If anyone has any insights, workarounds, or suggestions regarding this issue, please share them here.
2
1
1.1k
Oct ’23
APIs available or ways in which I can browse and read files from below mentioned sources?
Hi, so, what I'm looking to do is to provide a browsing screen for the below in my app i.e., construct the browsing UI for it and then when user selects a file here, I want to be able to open and read from it, example the 'on my iphone; tab in files has a specific path to it, if I use this to get folder structure and construct my own way of how the browse ui is supposed to look like. The storages/browsing options I want to show are, Local Storage: The folders shown when we go to the 'On my iPhone' tab in the Files app. Remote Storages like, Network Shared Folder/drive: Similar to the connect to server option that is shown in the Files app, and in files app on selecting files I get a path that I can work with, but I also wanted to know how this mount happens i.e., if file gets downloaded and changes synced or folder is actually mounted on file system. Cloud Storage: Like amazon s3, etc, can I provide a way to connect to these inapp and browse them and what would I get as path when I select a file. or can I show this option as locations in my app similar to the way it is shown in Files app. Sync Folders: Like onedrive, etc. Same as above can I have them in app or show them as locations Wireless Storage: Is there a way to detect a bluetooth storage being connected here, and how do I display the browse ui for it with my app? Removable Storage: Similarly, can I detect if a pendrive was connected to iPhone and show the browsing ui for it? what would the path look like FTP and http links: how to browse the former and stream data from the latter. Please let me know if you have any inputs on which is possible and how. Thanks in advance
5
0
371
Oct ’23
I'm missing something basic here but I am unable to to get the SwiftUI function to save a new file and delete the old one
it should be creating a new file and saving it, and then deleting the original file. iv'e attempted to have it load the UUID and by the title to avoid the need to even have the correct filename.... import SwiftUI struct file1DetailView: View { var file1: file1 @Binding var showFile1: Bool var saveFile1: ((file1) -> Void) @Environment(\.presentationMode) var presentationMode @State private var addFile1View: AddFile1View? var dateFormatter: DateFormatter { let formatter = DateFormatter() formatter.dateStyle = .long return formatter } var timeFormatter: DateFormatter = { let formatter = DateFormatter() formatter.timeStyle = .short return formatter }() var body: some View { ZStack { ScrollView { VStack { VStack{ HStack{ Text(file1.title) .font(.largeTitle.weight(.semibold)) .foregroundColor(.BrandGreen) .disabled(true) Spacer() } Spacer() .frame(height: 5) HStack{ Text(dateFormatter.string(from: file1.date)) .foregroundColor(.BrandGreen) .font(.subheadline.weight(.light)) Text(timeFormatter.string(from: file1.date)) .foregroundColor(.BrandGreen) .font(.subheadline.weight(.light)) Spacer() } Spacer() .frame(height: 15) Text(file1.description) .foregroundColor(.BrandGreen) .disabled(true) Spacer() .frame(height: 10) } .padding() .background(Color.white) .cornerRadius(30) Spacer() } Spacer() } .background( Image("calm-gradient") .resizable() .edgesIgnoringSafeArea(.all) ) VStack { Spacer() Button("Start file1") { let newFile1 = file1(title: file1.title, description: file1.description, date: file1.date, reflectionDate: Date(), preventible: false, Option1: "", Option2: "") addFile1View = AddFile1View(id: file1.id, file1: newFile1, saveFile1: saveFile1) showFile1 = true } .frame(maxWidth: .infinity) .padding(.vertical, 15) .foregroundColor(.white) .background(Color("BrandGreen")) } } .fullScreenCover(item: $addFile1View) { view in NavigationView { view .onDisappear { showFile1 = false presentationMode.wrappedValue.dismiss() } } } } } struct AddFile1View: View, Identifiable { var id: UUID @Environment(\.presentationMode) var presentationMode @State private var preventible = false @State private var Option1 = "" @State private var Option2 = "" @State private var reflectionDate = Date() var file1: file1 var saveFile1: ((file1) -> Void)? // AddFile1View initializer init(id: UUID, file1: file1, saveFile1: ((file1) -> Void)?) { self.id = id self.file1 = file1 self.saveFile1 = saveFile1 } var body: some View { VStack { Toggle("Preventible", isOn: $preventible) TextField("Option1", text: $Option1) TextField("Option2", text: $Option2) DatePicker("file1 Date", selection: $reflectionDate) Button("Save") { let newFile1 = file1(title: file1.title, description: file1.description, date: file1.date, reflectionDate: reflectionDate, preventible: preventible, Option1: Option1, Option2: Option2) saveFile1?(newFile1) presentationMode.wrappedValue.dismiss() } } .navigationTitle("Add file1") } } func saveFile1(file1: file1) { let encoder = JSONEncoder() let fm = FileManager.default let documentsDirectory = fm.urls(for: .documentDirectory, in: .userDomainMask).first! let file1sURL = documentsDirectory.appendingPathComponent("file1s.json") // Read the existing file1s from the file system var file1s: [file1] = [] if fm.fileExists(atPath: file1sURL.path) { do { let data = try Data(contentsOf: file1sURL) file1s = try JSONDecoder().decode([file1].self, from: data) } catch { print("Failed to read file1s from file system: \(error)") } } // Add the new file1 to the list file1s.append(file1) // Write the updated list back to the file system do { let data = try encoder.encode(file1s) try data.write(to: file1sURL) print("file1s saved to device: \(file1s)") print("file1s file URL: \(file1sURL)") } catch { print("Failed to save file1s: \(error)") } // Delete the old file1 file let oldFile1URL = documentsDirectory.appendingPathComponent("\(file1.id).json") if fm.fileExists(atPath: oldFile1URL.path) { do { try fm.removeItem(at: oldFile1URL) print("Deleted old file1 file: \(oldFile1URL.lastPathComponent)") } catch { print("Failed to delete old file1 file: \(error)") } } } struct file1DetailView_Previews: PreviewProvider { static var previews: some View { NavigationView { file1DetailView( file1: file1( title: "Example file1", description: "This is an example file1 description.", date: Date(), file1Date: Date(), preventible: true, Option1: "Example Option1", Option2: "Example Option2" ), showFile1: .constant(false), saveFile1: saveFile1 ) } } }
2
0
433
Sep ’23
`Bad file descriptor` when copying using hardlink flag
When I try to link a file on macOS, I get: $ cp -l release-source/release/examples/stubs-1-pubsub.test.js . cp: ./stubs-1-pubsub.test.js: Bad file descriptor This made it seem like the copying failed, but ls shows it went fine: $ ls -li release-source/release/examples/stubs-1-pubsub.test.js stubs-1-pubsub.test.js 9825657 -rw-r--r-- 2 carlerik staff 1072 26 sep 16:24 release-source/release/examples/stubs-1-pubsub.test.js 9825657 -rw-r--r-- 2 carlerik staff 1072 26 sep 16:24 stubs-1-pubsub.test.js A related post talks about this error coming from the file system, not the cp util itself. Creating a hard link using the ln command works fine, so the error must be due to something cp does that ln does not, so I fired up the console and captured messages hoping to see something. I cannot see that I do ... Does anyone have an idea what this is caused by? System information ❯ npx envinfo --system System: OS: macOS 13.5.2 CPU: (12) arm64 Apple M2 Max Memory: 4.24 GB / 64.00 GB Shell: 5.2.15 - /opt/homebrew/bin/bash ❯ diskutil list /dev/disk0 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *2.0 TB disk0 1: Apple_APFS_ISC Container disk1 524.3 MB disk0s1 2: Apple_APFS Container disk3 2.0 TB disk0s2 3: Apple_APFS_Recovery Container disk2 5.4 GB disk0s3
3
2
1.4k
Sep ’23
Path must be an absolute path: <> cannotCreateNode(path: "")
We are trying to save usdz file in file manager some time its saved but some time we are getting the error. Like: path.absoluteURL file:///var/mobile/Containers/Data/Application/6D14A430-47B4-45F2-9D0D-6C31588A6A03/Documents/2896837C-C7E0-4FA8-BFE2-21A59B26D801.usdz Warning: in SdfPath at line 151 of sdf/path.cpp -- Ill-formed SdfPath &lt;/2896837CC7E04FA8BFE221A59B26D801&gt;: syntax error Coding Error: in _IsValidPathForCreatingPrim at line 3338 of usd/stage.cpp -- Path must be an absolute path: &lt;&gt; cannotCreateNode(path: "/2896837CC7E04FA8BFE221A59B26D801") func saveFileLocal() { if let finalResult { let fm = FileManager.default var path = fm.urls(for: .documentDirectory, in: .userDomainMask).first! let fileName = "(UUID().uuidString).usdz" path.appendPathComponent(fileName) do { try finalResult.export(to: path.absoluteURL) } catch{ print(error) } } } func removeFiles() { var filePath = "" let fm = FileManager.default let path = fm.urls(for: .documentDirectory, in: .userDomainMask).first! do{ let content = try fm.contentsOfDirectory(atPath: path.path) for c in content{ filePath = path.appendingPathComponent(c).absoluteString if let url = URL(string: filePath){ try fm.removeItem(at: url) } } } catch{ print(error) } }
8
0
869
Oct ’23
unable to delete file because it's never found because.
my mind is shot. core data hasn't been my cup of tea. print("saveTrigger called with trigger: \(trigger)") let encoder = JSONEncoder() let fm = FileManager.default let documentsDirectory = fm.urls(for: .documentDirectory, in: .userDomainMask).first! let reflectionsURL = documentsDirectory.appendingPathComponent("reflections.json") let triggersDirectory = documentsDirectory.appendingPathComponent("Triggers") // Create a new reflections file if it doesn't exist if !fm.fileExists(atPath: reflectionsURL.path) { let emptyData = Data() fm.createFile(atPath: reflectionsURL.path, contents: emptyData, attributes: nil) } // Write the trigger to the reflections file do { let data = try encoder.encode(trigger) try data.write(to: reflectionsURL) print("Trigger saved to device: \(trigger)") print("Reflections file URL: \(reflectionsURL)") } catch { print("Failed to save trigger: \(error)") } // Find the trigger file with the UUID inside the file let triggerFileURL = triggersDirectory.appendingPathComponent("\(trigger.id).json") if fm.fileExists(atPath: triggerFileURL.path) { do { let data = try Data(contentsOf: triggerFileURL) let uuid = try JSONDecoder().decode(UUID.self, from: data) let uuidString = uuid.uuidString let matchingTriggerFileURL = triggersDirectory.appendingPathComponent("\(uuidString).json") if fm.fileExists(atPath: matchingTriggerFileURL.path) { try fm.removeItem(at: matchingTriggerFileURL) print("Trigger file deleted: \(matchingTriggerFileURL.lastPathComponent)") } else { print("Trigger file not found") } } catch { print("Error deleting trigger file: \(error.localizedDescription)") } } else { print("Trigger file not found") } }
6
0
568
Oct ’23
Change mobile data transfer
My APP is hybrid architecture, I transferred my test phone to a new phone, userdefault will be transferred, but the local storage of the front-end will not be transferred. Both(userdefault&amp;local storage) will be transferred when my colleagues transfer their personal phones. My test case Same model mobile phone Mobile phones with the same OS version Switch from a small OS version to a phone with a large OS version Switch from large OS version to mobile phone with small OS version The first three items are userdefault will be transferred, but local storage will not be transferred. The fourth item is that you will be asked to upgrade the OS version when transferring. Does anyone know any relevant information? Or are there any settings enabled?
0
0
271
Sep ’23
Opening AirDropped files in 3rd party apps in iOS 17
Since updating to iOS 17 there doesn't seem to be a way to automatically open files AirDropped into any applications. The files get downloaded to the Files application and you can open them from there, but previously you could open them straight in another application. There doesn't seem to be any documentation to this change. Is there still a way to open AirDropped files directly in a non-Apple published application?
16
9
5.4k
Oct ’23
macFUSE and autofs
I'm trying to use autofs to mount some macFUSE filesystems. However, autofs requires custom filesystems to provide /sbin/mount_* and this directory is not writable nor modifiable via synthentic.conf Using a launch agent or daemon is not desirable as there is a non-blocking delay before the filesystem gets mounted which causes a race condition. Is there any other option to let diskarbitrationd or autofs to automatically mount a macFUSE filesystem?
1
0
403
Jun ’24
macOS Sonoma 14 RC - Full Disk Access for app bundle is disabled after reboot (kTCCServiceSystemPolicyAllFiles)
Hi guys, has anyone seen this issue? When installing an application, which requires Full Disk Access (kTCCServiceSystemPolicyAllFiles), user enables this feature, but after reboot, OS automatically turns it off. Filed feedback in case it's a new issue. Any idea how to fix it? Any workaround to keep Full Disk Access enabled? Thanks.
16
0
3.5k
Dec ’23
Is there a way of accessing/viewing files in an iOS app's shared group location from a Mac?
My goal is to try and get a unified logging system set up where logging from an iOS app and its extensions (primarily a notification service extension) get written into one central repository. So I was planning on setting up CocoaLumberjack in the app and the extension to use the same file path/name, adding the group capability to the app and the extensions and specifying the shared group directory as the file path. By default, for an app, CocoaLumberjack writes its files to: var/mobile/Containers/Data/Application/05464D4A-20F6-4E1F-9DBC-3109C053A1E8/Library/Caches/Logs/ On a Mac using an application such as iExplorer the above file and be located and viewed and copied etc. For an extension, it writes them to: /var/mobile/Containers/Data/PluginKitPlugin/5542F5EA-EB3A-4728-B33E-4E57C1B7B3B4/Library/Caches/Logs/ Now if I configure Cocoalumberjack to instead write the logger file to the shared group directory, then that will be at: /private/var/mobile/Containers/Shared/AppGroup/6CD5AF2C-54C9-46EF-B831-997B1DD6664F/ However its not possible using iExplorer to access this location. Using a Mac connected to the iPhone, is there an app or tool etc., that will enable me to locate the log file if it's created in the above AppGroup location?
1
0
616
Sep ’23