Files and Storage

RSS for tag

Ask questions about file systems and block storage.

Pinned Posts

Posts under Files and Storage tag

206 Posts
Sort by:
Post not yet marked as solved
1 Replies
492 Views
Hi, I have an app on AppStore using UIDocumentBrowserViewController, see link below. I have "Settings" icon as a trailing Navigation Bar item menu. WIth iOS16, that icon is duplicated... No issue with iOS14 or 15. If I change from TrailingNavigation to LeadingNavigation, I don't see the issue. I have created a sample app and I can repro the same issue. Also, I checked another vendor app who I think is also using UIDocumentBrowserVIewController and I can see the same issue. Do I just raise a defect report? Thank you Maurice https://apps.apple.com/au/app/private-photo-video-document/id1625834751
Posted
by
Post not yet marked as solved
1 Replies
937 Views
My project contains an asset catalog with images that have emojis in their name. When trying to build in Xcode 15.0 beta (15A5160n) and 'Generate Asset Symbols' enabled the compiler crashes. Example error: error: 'ï' is not a valid digit in integer literal static let 0ï¸ â £Flat = ImageResource(name: "0ï¸ â £_flat", bundle: resourceBundle)
Posted
by
Post not yet marked as solved
0 Replies
473 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
7 Replies
2.2k Views
My app has the App Sandbox enabled and the File Access to Downloads folder is set to Read / Write in XCode. Upon clicking on a button the app should open the Finder displaying the Downloads folder. The following code snippet is used to launch the Finder if let inspirationsDirectory = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first{ NSWorkspace.shared.open(inspirationsDirectory) } On my MacOS it works well. After releasing the app to the AppStore and installing it on another Mac the following message is received upon clicking the button: The application does not have permission to open "Downloads" Which would be the solution to launch the Finder successfully ? Is it possible to launch the Finder showing the Downloads folder sorted by the Date Added column descending ?
Posted
by
Post marked as solved
5 Replies
1.1k Views
Hello. How in AppleScript to get a list of all files in all subfolders without any conditions? I understand I need to use find. What the code will look like without any conditions, I need to get absolutely all the files: no matter the extension, no matter the file name. The only thing I would like is not to receive hidden files.
Posted
by
Post not yet marked as solved
0 Replies
628 Views
Hello, I'm a novice developer for iOS using SwiftUI. I want to create a way for users of my app to upload 3D models onto their account and dynamically load them into a scene upon selecting it from their library of saved 3D models. Is there a way to do this? I'm aware of the pass-through method, but this requires having models installed into the build of the app before launching it. Can someone help or point me in the right direction? Thank you!
Posted
by
Post not yet marked as solved
7 Replies
1k Views
When we try to run our code that uses the containerURLForSecurityApplicationGroupIdentifier function, the returned value is null if the program was run with root privileges. (when we run the code like a normal user, it is works as expected) The following code was run: NSFileManager* fileManager = [NSFileManager defaultManager]; if(!fileManager) { return “”; } NSURL* containerURL = [fileManager containerURLForSecurityApplicationGroupIdentifier:[NSString stringWithUTF8String:group_name]]; if(!containerURL) { return “”; } -> we will receive the right containerURL: /Users/{user}/Library/Group Containers/{group_name} If the same code will be run with root/admin privileges the containerURL will be NULL. With an older version of MacOS the output result was the following: normal user: /Users/{user}/Library/Group Containers/{group_name} root user : /private/var/root/Library/Group Containers/{group_name}
Posted
by
Post not yet marked as solved
1 Replies
568 Views
Hi Team, We have developed an Daemon process using Microsoft Windows Worker Service written in .NET Core. On the first run the daemon process supposed to copy an sqlite database file on our specified path and then it will also generate some image files and save them on the specified path. The daemon process is working perfectly fine in DEBUG mode. However whenever we launch the daemon process in RELEASE mode via launchd command, the daemon process is unable to copy or write the files on the specified path. It looks like in the RELEASE mode the exe file of daemon needs file writing permissions to copy and write the files. Can you please guide us how can we resolve this issue and grant the file writing rights to the daemon process to work? Thank you. Asif from Techliance.
Posted
by
Post not yet marked as solved
4 Replies
708 Views
I have been having some issues saving URLs. I want to be able to save a list of URLs with their bookmark data so that the app can still access some folders after reboot. The folders are on the desktop. I have read and write access to the disk, as was set in the app sandbox settings (User Selected File). It works for as long as the app is open but as soon as I restart it the URLs seem to go invalid, or at least it says that I don't have permission to access the folder that is selected. I then have to clear the urls and re-select them. You can ignore the blacklist thing as I am not using it in the tests I am running. You can also ignore the sources_list and dest_list they are for the GUI. Here is how the user selects the file: func inputBrowseClicked(source_or_dest: String) { let inputPanel = NSOpenPanel() if source_or_dest == "blacklist" { inputPanel.canChooseFiles = true inputPanel.canChooseDirectories = false } else { inputPanel.canChooseFiles = false inputPanel.canChooseDirectories = true } let userChoice = inputPanel.runModal() switch userChoice{ case .OK : if let inputFileChosen = inputPanel.url { do { // Start accessing a security-scoped resource. _ = inputFileChosen.startAccessingSecurityScopedResource() let bookmarkData = try inputFileChosen.bookmarkData(options: .withSecurityScope, includingResourceValuesForKeys: nil, relativeTo: nil) if source_or_dest == "blacklist" { add_blacklist_file(file: inputFileChosen) } else { add_sources_or_dests_url(url_to_add: bookmarkData, sources_or_dests: source_or_dest) } inputFileChosen.stopAccessingSecurityScopedResource() sources_list = get_sources_or_dests_urls(sources_or_dests: "source") dest_list = get_sources_or_dests_urls(sources_or_dests: "dest") } catch (let error) { print(error) return } return } case .cancel : return default: return } return } Here is the function that adds one URL to the list: func add_sources_or_dests_url(url_to_add: Data, sources_or_dests: String) { // load currently stored list if var source_dest_urls = userDefaults.array(forKey: "saved_"+sources_or_dests) as? [Data] { // is the url already in the list if !(source_dest_urls.contains(url_to_add)){ source_dest_urls.append(url_to_add) userDefaults.set(source_dest_urls, forKey: "saved_"+sources_or_dests) userDefaults.set(source_dest_urls.count,forKey: sources_or_dests+"_index") } } else { userDefaults.set([url_to_add], forKey: "saved_"+sources_or_dests) userDefaults.set(0,forKey: sources_or_dests+"_index") } } Here is the function of reading the URLs which I use every time I want to access them which is why I don't understand how it can work until I restart the app. func get_sources_or_dests_urls(sources_or_dests: String) -> [URL] { // load currently stored list var source_dest_urls: [URL] = [] if let source_dest_urls_data = userDefaults.array(forKey: "saved_"+sources_or_dests) as? [Data] { for bookmarkData in source_dest_urls_data { do { var isStale = false let url = try URL(resolvingBookmarkData: bookmarkData, options: [.withSecurityScope], bookmarkDataIsStale: &isStale) guard !isStale else { print("Stale URL: "+sources_or_dests) return source_dest_urls } source_dest_urls.append(url) } catch (let error) { print(error) print(sources_or_dests) } } return source_dest_urls } else { return [] } } The funny thing is that when I call the (folder_url).startAccessingSecurityScopedResouce it returns True Here is an example of the error: file:///Users/georgeturner/Desktop/Sorted_test/DJI_0274.JPG 2023-06-25 15:20:15.198258+0100 Camera Import[74663:1326092] open on /Users/georgeturner/Desktop/16-07-2022/DJI_0274.JPG: Operation not permitted Error Domain=NSCocoaErrorDomain Code=513 "“DJI_0274.JPG” couldn’t be copied because you don’t have permission to access “Sorted_test”." UserInfo={NSSourceFilePathErrorKey=/Users/georgeturner/Desktop/16-07-2022/DJI_0274.JPG, NSUserStringVariant=( Copy ), NSDestinationFilePath=/Users/georgeturner/Desktop/Sorted_test/DJI_0274.JPG, NSFilePath=/Users/georgeturner/Desktop/16-07-2022/DJI_0274.JPG, NSUnderlyingError=0x600002641170 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
Posted
by
Post marked as solved
1 Replies
702 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
2 Replies
580 Views
I'm new to the scene. I'm learning to be a software dev but this is my first venture into the MacOs scene. We use Macs in the computer labs at my workplace and I wanted to create a python app that detects if the signed in user is taking up more than 15Gb of the storage on the Mac. The program works great and I've built in some extra functionality so it works with our other management systems but I've run into an issue. The program will need to run on login and if the app runs for the first time it asks them to allow the app to access their data (scan documents folder, desktop folder, pictures folder etc.) and this kind of defeats the purpose of the app as we want to enforce and monitor without the students having the ability to break the program. If the user just clicks no on all of the prompts for permissions the app won't detect storage and I'm back to square one. I've tried adding a info.plist which I though would have fixed the issue but no luck. Any advice on how I can give the program elevated permissions or run something like a sudo instance that ignores or forces the permissions. The logic in my code can be changed too.. no biggy. Just need to find a solution and not spend any money on licenses or API's. Any advice will be greatly appreciated. Alex
Posted
by
Post not yet marked as solved
17 Replies
1.4k Views
We have an App Group defined in our entitlements file so that two pieces of our software, a management GUI and a VPN extension, can write files to the same location. This is not just for regular log files. There's data we want to record which isn't appropriate for the system logs. What we're seeing on the iOS and macOS betas is that the write() file always fails, and we end up with \0s written to the file instead of the data. This is true both with the shipping versions of our applications on the App Store and with builds made with Xcode 15 and run on the devices in the debugger. Happens from both the Network Extension and the management application. Both macOS and iOS. Shipping apps and freshly built with latest tools. There's nothing we see in the Console logs that would appear to explain this. I didn't see anything in the release notes that would address this, but I could easily have missed something. Anyone else seen this?
Posted
by
Post not yet marked as solved
12 Replies
714 Views
Hi, I have an app that was sharing the same package ID as its demo, though they had separate data folders in Application Support. I recently found out that deleting one or the other app (demo or full) was simultaneously deleting files in one or the other data file, but without any obvious logic. This could explain why some update setups created with Packages end up removing some files/folders from the destination data folder. All this is very dangerous because I don't want an update to wipe the work of some of my users, so I need to perfectly understand why this happens and what are the exact rules. Could you please point me to any specific documentation on that? Thanks a lot. Mariano
Posted
by
Post marked as solved
2 Replies
378 Views
So basically I can tell that the images are being saved by the system (it shows it on the debug terminal) however whenever I close, and then reopen the app the images firstly aren't there at all but also whenever I search the address name I saved them as... I have tried diagonsing the problem by changing UUID's, changing PNGs to JPGS - no matter what I do it does not show once the application has closed. I think it might have to do with how the image are .HEIF (apple's standard) but I don't have any concrete evidence to back this up. If anyone can help it would be greatly apperciated. import SwiftUI import MapKit import CoreLocation struct ContentView: View { @StateObject private var mapAPI = MapAPI() @State private var text = "" @State private var locationInfo: String = "" @State private var showLocationInfo = false @State private var imageUrls = [String]() // Array to store image URLs @State private var showImagePicker = false @State private var showCamera = false @State private var selectedImage: UIImage? @State private var images: [UIImage] = [] @State private var selectedImageSourceType: UIImagePickerController.SourceType? struct ImageInfo: Identifiable { let id = UUID() let address: String let imageUrl: URL } ... // Page 2: Photo VStack { Spacer() Menu { Button(action: { showImagePicker = true selectedImageSourceType = .photoLibrary }) { Label("Choose from Library", systemImage: "photo") } Button(action: { showImagePicker = true selectedImageSourceType = .camera }) { Label("Take Photo", systemImage: "camera") } } label: { Text("Memories") .font(.title) .foregroundColor(.black) } .padding() .sheet(isPresented: $showImagePicker, onDismiss: loadImage) { ImagePicker(sourceType: selectedImageSourceType ?? .photoLibrary) { image in selectedImage = image } } if !images.isEmpty { ScrollView { LazyVGrid(columns: [GridItem(.adaptive(minimum: 200, maximum: 700))], spacing: 20) { ForEach(images, id: \.self) { image in Image(uiImage: image) .resizable() .aspectRatio(contentMode: .fill) .frame(height: UIScreen.main.bounds.height / 5) .frame(width: UIScreen.main.bounds.width - 60) .cornerRadius(15) } } .padding() } } else { Text("No photos available") .foregroundColor(.gray) } } .tabItem { Image(systemName: "camera") Text("Memories") } .tag(1) } .accentColor(.black) } @State private var encodedAddress = "" func fetchLocationInfoFromWikipedia(for address: String) { guard let encodedAddress = address.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro=true&explaintext=true&titles=\(encodedAddress)") else { self.encodedAddress = encodedAddress return } URLSession.shared.dataTask(with: url) { data, _, error in if let data = data { if let responseJSON = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let query = responseJSON["query"] as? [String: Any], let pages = query["pages"] as? [String: Any], let page = pages.keys.first, let pageData = pages[page] as? [String: Any], let extract = pageData["extract"] as? String { DispatchQueue.main.async { self.locationInfo = extract } } } } .resume() } func openWebsite(_ urlString: String) { if let encodedAddress = self.text.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: urlString + encodedAddress) { UIApplication.shared.open(url) } } func loadImage() { guard let selectedImage = selectedImage else { return } images.append(selectedImage) saveImage(selectedImage) self.selectedImage = nil } func saveImage(_ image: UIImage) { let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let filename = UUID().uuidString let fileURL = documentsDirectory.appendingPathComponent(filename) if let imageData = image.jpegData(compressionQuality: 1.0) { do { try imageData.write(to: fileURL) print("Image saved at: \(fileURL)") } catch { print("Error saving image data: \(error.localizedDescription)") } } } func loadSavedImages() { let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! do { let fileURLs = try FileManager.default.contentsOfDirectory(at: documentsDirectory, includingPropertiesForKeys: nil, options: []) let imageFiles = fileURLs.filter { $0.pathExtension == "png" || $0.pathExtension == "png" } for fileURL in imageFiles { if let imageData = try? Data(contentsOf: fileURL), let image = UIImage(data: imageData) { images.append(image) } } } catch { print("Error loading saved images: \(error.localizedDescription)") } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Posted
by
Post not yet marked as solved
1 Replies
431 Views
So basically I can tell that the images are being saved by the system (it shows it on the debug terminal) however whenever I close, and then reopen the app the images firstly aren't there at all but also whenever I search the address name I saved them as... I have tried diagonsing the problem by changing UUID's, changing PNGs to JPGS - no matter what I do it does not show once the application has closed. I think it might have to do with how the image are .HEIF (apple's standard) but I don't have any concrete evidence to back this up. If anyone can help it would be greatly apperciated. import SwiftUI import MapKit import CoreLocation struct ContentView: View { @StateObject private var mapAPI = MapAPI() @State private var text = "" @State private var locationInfo: String = "" @State private var showLocationInfo = false @State private var imageUrls = [String]() // Array to store image URLs @State private var showImagePicker = false @State private var showCamera = false @State private var selectedImage: UIImage? @State private var images: [UIImage] = [] @State private var selectedImageSourceType: UIImagePickerController.SourceType? struct ImageInfo: Identifiable { let id = UUID() let address: String let imageUrl: URL } ... // Page 2: Photo VStack { Spacer() Menu { Button(action: { showImagePicker = true selectedImageSourceType = .photoLibrary }) { Label("Choose from Library", systemImage: "photo") } Button(action: { showImagePicker = true selectedImageSourceType = .camera }) { Label("Take Photo", systemImage: "camera") } } label: { Text("Memories") .font(.title) .foregroundColor(.black) } .padding() .sheet(isPresented: $showImagePicker, onDismiss: loadImage) { ImagePicker(sourceType: selectedImageSourceType ?? .photoLibrary) { image in selectedImage = image } } if !images.isEmpty { ScrollView { LazyVGrid(columns: [GridItem(.adaptive(minimum: 200, maximum: 700))], spacing: 20) { ForEach(images, id: \.self) { image in Image(uiImage: image) .resizable() .aspectRatio(contentMode: .fill) .frame(height: UIScreen.main.bounds.height / 5) .frame(width: UIScreen.main.bounds.width - 60) .cornerRadius(15) } } .padding() } } else { Text("No photos available") .foregroundColor(.gray) } } .tabItem { Image(systemName: "camera") Text("Memories") } .tag(1) } .accentColor(.black) } @State private var encodedAddress = "" func fetchLocationInfoFromWikipedia(for address: String) { guard let encodedAddress = address.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro=true&explaintext=true&titles=\(encodedAddress)") else { self.encodedAddress = encodedAddress return } URLSession.shared.dataTask(with: url) { data, _, error in if let data = data { if let responseJSON = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let query = responseJSON["query"] as? [String: Any], let pages = query["pages"] as? [String: Any], let page = pages.keys.first, let pageData = pages[page] as? [String: Any], let extract = pageData["extract"] as? String { DispatchQueue.main.async { self.locationInfo = extract } } } } .resume() } func openWebsite(_ urlString: String) { if let encodedAddress = self.text.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: urlString + encodedAddress) { UIApplication.shared.open(url) } } func loadImage() { guard let selectedImage = selectedImage else { return } images.append(selectedImage) saveImage(selectedImage) self.selectedImage = nil } func saveImage(_ image: UIImage) { let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let filename = UUID().uuidString let fileURL = documentsDirectory.appendingPathComponent(filename) if let imageData = image.jpegData(compressionQuality: 1.0) { do { try imageData.write(to: fileURL) print("Image saved at: \(fileURL)") } catch { print("Error saving image data: \(error.localizedDescription)") } } } func loadSavedImages() { let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! do { let fileURLs = try FileManager.default.contentsOfDirectory(at: documentsDirectory, includingPropertiesForKeys: nil, options: []) let imageFiles = fileURLs.filter { $0.pathExtension == "png" || $0.pathExtension == "png" } for fileURL in imageFiles { if let imageData = try? Data(contentsOf: fileURL), let image = UIImage(data: imageData) { images.append(image) } } } catch { print("Error loading saved images: \(error.localizedDescription)") } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }
Posted
by
Post not yet marked as solved
1 Replies
568 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
412 Views
I'm working on a functionality on my code - where it will add a flag to the map once an image is added to the app (via the second page, not shown) but it just doesn't perform how I want. Basically the photo saving is working perfectly and shows via the terminal where and how something is saving and the flags or pins that are added to the map also do save however just to see the you have to go to the second page (press on it) and come back to page 1 (Map) to see them - I just want to be able to see them from the start of the app. I tried init() { loadSavedImages(for: "") loadSavedImageLocations() but this doesn't really help much - if anyone can help it would really be apperciated. import SwiftUI import MapKit import CoreLocation import UIKit struct MapView: UIViewRepresentable { @Binding var region: MKCoordinateRegion @Binding var mapType: MKMapType var imageLocations: [CLLocationCoordinate2D] @Binding var weatherInfo: String @Binding var showWeatherInfo: Bool func makeUIView(context: Context) -> MKMapView { let mapView = MKMapView() mapView.setRegion(region, animated: true) mapView.mapType = mapType // Add annotations for image locations mapView.addAnnotations(imageLocations.map { location in let annotation = ImageAnnotation(coordinate: location) return annotation }) ... class ImageAnnotation: NSObject, MKAnnotation { let coordinate: CLLocationCoordinate2D init(coordinate: CLLocationCoordinate2D) { self.coordinate = coordinate super.init() } } struct ImageLocation: Codable { let latitude: Double let longitude: Double init(coordinate: CLLocationCoordinate2D) { self.latitude = coordinate.latitude self.longitude = coordinate.longitude } ... private init() {} func saveImageLocation(_ location: CLLocationCoordinate2D) { var savedLocations = getSavedLocations() let imageLocation = ImageLocation(coordinate: location) savedLocations.append(imageLocation) do { let data = try JSONEncoder().encode(savedLocations) let fileURL = documentsDirectory.appendingPathComponent("ImageLocations.json") try data.write(to: fileURL) } catch { print("Error saving image locations: \(error.localizedDescription)") } } func getSavedLocations() -> [ImageLocation] { let fileURL = documentsDirectory.appendingPathComponent("ImageLocations.json") guard let data = try? Data(contentsOf: fileURL) else { return [] } ... struct ImageInfo: Identifiable { let id = UUID() let address: String let imageUrl: URL } init() { loadSavedImages(for: "") loadSavedImageLocations() // Load saved image locations when the app launches } ... MapView(region: $mapAPI.region, mapType: $mapType, imageLocations: imageLocations, weatherInfo: $weatherInfo, showWeatherInfo: $showWeatherInfo) .ignoresSafeArea() .... // Page 2: Photo VStack { Spacer() Menu { Button(action: { showImagePicker = true selectedImageSourceType = .photoLibrary }) { Label("Choose from Library", systemImage: "photo") } Button(action: { showImagePicker = true selectedImageSourceType = .camera }) { } } label: { Text("Memories") .font(.title) ... .onAppear { loadSavedImages(for: text) loadSavedImageLocations() ... func saveImage(_ image: UIImage, for address: String) { let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! // Generate a unique filename based on address and timestamp let timestamp = Int(Date().timeIntervalSince1970) let filename = "\(address)_\(timestamp).jpg" let fileURL = documentsDirectory.appendingPathComponent(filename) if let imageData = image.jpegData(compressionQuality: 0.5) { do { try imageData.write(to: fileURL) print("Image saved at: \(fileURL)") // Add the file URL to the imageUrls array let imageInfo = ImageInfo(address: address, imageUrl: fileURL) imageUrls.append(imageInfo) } catch { print("Error saving image data: \(error.localizedDescription)") } // Append the location to the imageLocations array if let location = mapAPI.locations.last?.coordinate { imageLocations.append(location) } } } func loadSavedImages(for address: String) { images = [] // Clear the existing images let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! do { let fileURLs = try FileManager.default.contentsOfDirectory(at: documentsDirectory, includingPropertiesForKeys: nil, options: []) // Filter and get file URLs for the images associated with the specified address let imageFiles = fileURLs .filter { $0.pathExtension == "jpg" } .filter { $0.lastPathComponent.contains(address + "_") } for fileURL in imageFiles { if let imageData = try? Data(contentsOf: fileURL), let image = UIImage(data: imageData) { images.append(image) } } } catch { print("Error loading saved images: \(error.localizedDescription)") } } func loadSavedImageLocations() { let savedLocations = ImageDataManager.shared.getSavedLocations() imageLocations = savedLocations.map { $0.locationCoordinate } } func deleteImage(at index: Int) { let imageInfo = imageUrls[index] let fileManager = FileManager.default do { try fileManager.removeItem(at: imageInfo.imageUrl) images.remove(at: index) imageUrls.remove(at: index) } catch { print("Error deleting image: \(error.localizedDescription)") } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } }
Posted
by
Post not yet marked as solved
0 Replies
1.8k Views
File system changes introduced in iOS 17 As part of iOS 17, tvOS 17, and watchOS 10, the system has reorganized where applications and their data containers are stored. In previous systems, both lived within the same volume but, starting in iOS 17, they will be stored on different volumes. What does this mean for you? Copying large amounts of data from the app bundle to a data container will take longer than in previous versions of iOS. Previously that copy would have occurred as an APFS file clone, but now the operation will occur as a standard copy, which may take much significantly longer. Because the data will need to be fully duplicated, storage usage will increase more than was the case in previous versions. You should minimize the data they copy out of their app bundle and avoid any unnecessary duplication of data between the app bundle and data container. When upgrading from previous system version, splitting the data into separate volumes may mean that there is insufficient space for all existing apps and their data. If this occurs, the app's data container will remain on the device, preserving the user's data, while the app bundle itself is removed using the same mechanism as "Offload Unused Apps". The user can then restore the app once they've freed sufficient space for the app to install. Revision History 2023-07-11 First posted
Posted
by
DTS Engineer