Post not yet marked as solved
I'm struggling with writing to an iCloud file. I want my IOS app to open files on the iCloud driver. I get the above error upon return from fopen(filename, "w"). Further, the container name (iCloud.TrackInstructor) appears in red under the iCloud stanza of the Signings & Capabilities page.
I can see my container under the CloudKit page of my Apple Developer account. However, below, it states:
Error loading container details.
Also in red.
FWIW, my app is trying to open:
/private/var/mobile/Library/Mobile%20Documents/iCloud~TrackInstructor/Documents/nav_detailed_file_20220719_111330.csv
I have IOS 15.5 and Xcode 13.4.1.
I'm struggling. Help or ideas are appreciated.
Post not yet marked as solved
I am wondering if Apple allows us to get access to iCloud Mail inbox and read user's messages in iOS application?
I did a lot of research but couldn't find a concrete answer.
For example, on Google, this is possible by using OAuth.
Post not yet marked as solved
I believe that if I rename a file, I'm supposed to do that inside a coordinated write on the parent directory - right?
So say I have a file /path/to/folder/f1 and I want to rename it (in the same directory) as /path/to/folder/f2.
I do a coordinated write (with the forMoving option) on the directory /path/to/folder. That passes me a possibly different path to the directory, right? Say I get /path/to/different.
Question: what rename should I actually do? Do I need to construct from and to paths based on the different path that is passed to the accessor? I.e. do I
rename from /path/to/folder/f1 to /path/to/folder/f2
or rename from /path/to/different/f1 to /path/to/different/f2
or some other combination?
Do NSFileManager's renaming methods do anything special in this regard? Can I use e.g. std::filesystem::rename()?
I am interested in both local documents that are visible e.g. in the Files app, and iCloud Drive documents, if that makes any difference.
Thanks!
Post not yet marked as solved
Dear Experts,
Is there a way to limit an NSMetadataQuery to one iCloud container, in an app with more than one?
It seems to me that setting the scope to NSMetadataQueryUbiquitousDocumentsScope will probably return either the contents of the first (default) container, or all containers
Is there something I can put in the predicate? Maybe I have to try to match URLs that start-with the container's own URL?
Post not yet marked as solved
I'm struggling to find a way to monitor the progress (in percent, or bytes) of a download from iCloud Drive. I.e. files outside of the app's ubiquitous document folder. Our app provides a directory browser (which is accessed using a security scoped bookmark granted by the user). In this browser we want to enable users to download files from iCloud analogous to the user experience provided in Files.app.
It seems that NSMetaDataQuery would be the right way to go nowadays. However i don't get any results for queries outside of my own app container. I suppose that's a permission problem?
Luckily we can get most of what we need using url's resource values. Also initiating and canceling a download works using NSFileManager. However i found now suitable way of determining a download's progress. NSURLUbiquitousItemPercentDownloadedKey is deprecated and doesn't give any results.
Did i overlook something? Is there a way to get NSMetaDataQuery working with security scoped bookmarks to folders?
Post not yet marked as solved
I'm using NSMetadataQuery and NotificationCenter, to perform file downloading from iCloud.
Construct NSMetadataQuery with predicate NSPredicate(format: "%K == %@", NSMetadataItemFSNameKey, filename)
Observe NSMetadataQueryDidUpdate & NSMetadataQueryDidFinishGathering using NotificationCenter.
Check file status NSMetadataUbiquitousItemDownloadingStatusKey. If the file is up-to-date, copy the file to destination directory, and jump to step 6.
Perform FileManager.default.startDownloadingUbiquitousItem
Receive file downloading status in NSMetadataQueryDidUpdate callback. If the file is up-to-date, copy the file to destination directory, and jump to step 6.
Perform cleanup by removing all observers.
If file is not available in iCloud, no notification received.
We wish, even if the file doesn't exist, we will still be notified, so that we have chance to perform cleanup (step 6)
Here's the code snippet to perform iCloud download.
DownloadManager.swift
class DownloadManager {
static let INSTANCE = DownloadManager()
var downloaders = [iCloudDocumentDownloader]()
private init() {
}
func append(filename: String, destinationDirectory: URL) {
let downloader = iCloudDocumentDownloader(filename: filename, destinationDirectory: destinationDirectory)
downloaders.append(downloader)
}
func removeAll(_ downloader: iCloudDocumentDownloader) {
downloaders.removeAll{$0 === downloader}
}
}
iCloudDocumentDownloader.swift
class iCloudDocumentDownloader {
private let filename: String
private let destinationDirectory: URL
private let metadataQuery = NSMetadataQuery()
private static let operationQueue: OperationQueue = {
let operationQueue = OperationQueue()
operationQueue.name = "com.yocto.wenote.operationQueueForiCloudDocument"
operationQueue.maxConcurrentOperationCount = 1
operationQueue.qualityOfService = .userInitiated
return operationQueue
}()
deinit {
NotificationCenter.default.removeObserver(self)
}
private func bye() {
DownloadManager.INSTANCE.removeAll(self)
}
init(filename: String, destinationDirectory: URL) {
self.filename = filename
self.destinationDirectory = destinationDirectory
metadataQuery.operationQueue = iCloudDocumentDownloader.operationQueue
metadataQuery.predicate = NSPredicate(format: "%K == %@", NSMetadataItemFSNameKey, filename)
metadataQuery.searchScopes = [
NSMetadataQueryUbiquitousDocumentsScope
]
NotificationCenter.default.addObserver(self, selector: #selector(didUpdate), name: NSNotification.Name.NSMetadataQueryDidUpdate, object: metadataQuery)
NotificationCenter.default.addObserver(self, selector: #selector(didFinishGathering), name: NSNotification.Name.NSMetadataQueryDidFinishGathering, object: metadataQuery)
metadataQuery.start()
}
@objc func didUpdate(_ notification: Notification) {
guard let metadataQuery = notification.object as? NSMetadataQuery else { return }
metadataQuery.enumerateResults { [weak self] (item: Any, index: Int, stop: UnsafeMutablePointer<ObjCBool>) in
guard let self = self else { return }
guard let metadataItem = item as? NSMetadataItem else { return }
guard let status = metadataItem.value(forAttribute: NSMetadataUbiquitousItemDownloadingStatusKey) as? String else { return }
guard let url = metadataItem.value(forAttribute: NSMetadataItemURLKey) as? URL else { return }
if status == NSMetadataUbiquitousItemDownloadingStatusCurrent {
if !destinationDirectory.createCompleteDirectoryHierarchyIfDoesNotExist() {
self.bye()
// Early return.
return
}
let destinationURL = destinationDirectory.appendingPathComponent(filename, isDirectory: false)
do {
try FileManager.default.copyItem(at: url, to: destinationURL)
} catch {
error_log(error)
}
self.bye()
} else if let error = metadataItem.value(forAttribute: NSMetadataUbiquitousItemDownloadingErrorKey) as? NSError {
error_log(error)
self.bye()
} else {
}
}
}
@objc func didFinishGathering(_ notification: Notification) {
guard let metadataQuery = notification.object as? NSMetadataQuery else { return }
metadataQuery.enumerateResults { [weak self] (item: Any, index: Int, stop: UnsafeMutablePointer<ObjCBool>) in
guard let self = self else { return }
guard let metadataItem = item as? NSMetadataItem else { return }
guard let status = metadataItem.value(forAttribute: NSMetadataUbiquitousItemDownloadingStatusKey) as? String else { return }
guard let url = metadataItem.value(forAttribute: NSMetadataItemURLKey) as? URL else { return }
if status == NSMetadataUbiquitousItemDownloadingStatusCurrent {
if !destinationDirectory.createCompleteDirectoryHierarchyIfDoesNotExist() {
self.bye()
// Early return.
return
}
let destinationURL = destinationDirectory.appendingPathComponent(filename, isDirectory: false)
do {
try FileManager.default.copyItem(at: url, to: destinationURL)
} catch {
error_log(error)
}
self.bye()
} else if let error = metadataItem.value(forAttribute: NSMetadataUbiquitousItemDownloadingErrorKey) as? NSError {
error_log(error)
self.bye()
} else {
do {
try FileManager.default.startDownloadingUbiquitousItem(at: url)
} catch {
error_log(error)
self.bye()
}
}
}
}
}
Post not yet marked as solved
I am attempting to erase everything from my old iPhone after I have transferred all my content and settings to the new one. However, the process seems to get stuck when it tries to “upload data” to iCloud and when I press the “skip backup” button, it still remains frozen (whether or not I press skip backup it will not pass this stage of the erase process). I have tried force restarting my phone and that didn’t seem to work. Does anyone have advice or a suggestion?
Post not yet marked as solved
Hey,
I wanted to ask if it is possible to download all the content of iCloud automatically (or just the images). Is there any way to automatically request your data or something like that?
Post not yet marked as solved
Hi,
So after updating my mac to Catalina few week ago, the system preferences was keeping asking to "accept terms and condition" but for some reason I could not open the tab to accept them.
Since I could not remember the password,I logged off my apple ID and I re-set the password. Everything was absolutely unchanged. Suddenly after log back in, all the folders and document I had in my desktop (that technically were in iCloud) disappeared for 20min to then reappear suddenly without me doing nothing.
Today I was open the folder in my desktop searching for a document and it is gone, it is not there anymore. I went to iCloud.com and ALL the files there were from either mid 12/2021 or early 01/2022. that's it. lost 5 month of work.
If I open one of the file that I opened and modified yesterday to restore a more recent version, it just gives me the one from January and none of these form yesterday.
I did try to go on iCloud and restore the file but it says "no file to restore" and also there was no file in "deleted". Anyone can help?
Camilla
Post not yet marked as solved
My app backup the data to iCloud or sync with user device through the user iCloud account using NSPersistentCloudKitContainer privateDataBase. The main problem is, when user install the app I need to know if user has data in iCloud or not according this information, I let user to setup account or fetch the existing account, since it takes too long to fetch with local CoreData, I am trying to find a way to fetch directly from iCloud through CloudKit, since I am new in CloudKit, I don't know how to fetch data from CloudKit any help appreciate.
Post not yet marked as solved
Is it possible to use iCloud to backup files that are currently stored locally so that those files appear on other devices? And can this be done automatically with the user having to take explicit action to do periodic backups? I have an existing app in which the user can create local files. If I add iCloud support I do not want the users to have to move all their files to iCloud Drive first. I do not want to disrupt the current usage more than necessary.
Post not yet marked as solved
Is using CoreData + CloudKit to store text notes and iCloud Document to store note image attachments as image files a good design approach?
Currently, I have almost finished implementing the app to store text notes as Core Data and note image attachments as image files.
I like to provide iCloud storage support to the app.
I come across a few app examples
https://www.raywenderlich.com/13219461-getting-started-with-core-data-and-cloudkit
https://developer.apple.com/documentation/coredata/synchronizing_a_local_store_to_the_cloud
Both examples are using CoreData + CloudKit to store the image as SQLite blob binary data which CoreData will perform such task automatically)
I'm aware that when storing the binary image into CoreData, CoreData is smart enough to choose either to store it as a binary blob in SQLite, or an external file.
However, I am a little skeptical about such an approach
We are using Kingfisher for smooth image loading in the collection view. If the image data are not in a regular flat-file, how can we integrate CoreData's blob data with Kingfisher?
Storing images in CoreData seems like a black box. If something goes wrong in between, it is hard to debug where and how goes wrong.
We like to provide alternative cloud storage (using cloud S3 storage to store SQLite files and multiple images) for the app. So, saving the image as flat files will make such an effort easier.
Some related discussion on storing the image in DB vs flat files - https://stackoverflow.com/questions/3748/storing-images-in-db-yea-or-nay
I would prefer
Only use CoreData + CloudKit to store the text note and file path.
The image file will store in both the app folder and the iCloud document folder (so that it syncs seamlessly to iCloud). If the required images are not in the app folder (App uninstall, then re-install), the app will try to copy the image file from the iCloud document
I was wondering, anyone of you has tried such a design in your app? Do you find it is a good approach based on your experience?
Thanks.
Post not yet marked as solved
Hi I am trying to publish parts ore my hole iCloud on a Website. I am looking for days to finde a way to do that. I am hosting the Website from a Mac mini with macOS X Server. The easiest way I see is with CloudKit. Has anyone an idea?
In the end something like https://www.icloud.com would be exactly what I want. But how? XD
Ps: i am open for everything. Can be done over app (Xcode) can be done with server stuff what i have no idea about... Everything
Post not yet marked as solved
I have a macOS app that synchronizes some files in the app's iCloud container, outside the Documents folder. Changes to these files are monitored with a NSMetadataQuery using a search scope of NSMetadataQueryUbiquitousDataScope. The NSMetadataQuery instance uses an operation queue for notifications and I'm calling startQuery on the instance's operation queue.
As of macOS 12.3, for a subset of my users, the NSMetadataQueryDidFinishGatheringNotification notification is never sent after starting the query. The NSMetadataQueryDidStartGatheringNotification and NSMetadataQueryGatheringProgressNotification notifications are posted.
For those affected who have multiple Macs, each of their Macs seems to be affected by this, as if it is a problem specific to the iCloud container for my app, for that user.
I'm unable to reproduce the issue on my personal machine.
Has anyone else noticed this behavior since macOS 12.3 was released?
Post not yet marked as solved
We have a macOS app, SheetPlanner, that supports sharing a document with other people for collaboration, via iCloud Drive.
When someone shares a document in Apple Pages, e.g. via email, and someone else clicks the link to open the document, the panel offers to open the document "in Pages", and opens the document directly in the app:
But when we do the same with a SheetPlanner document, it is missing the "in SheetPlanner" part, and instead displays the document in the Finder:
What are we missing? How can we get the iCloud sharing mechanism to offer to open in the app?
Here's a video that demonstrates this:
https://dropbox.com/s/bh9ipmn3h9ucpfc/Pages%20V%20SheetPlanner%20Sharing%20Behaviour.mov?dl=0
Post not yet marked as solved
http://kzmcherry77@gmail.com
Support
linkText
Post not yet marked as solved
How can I have a clear trazability from my cloud files some time afterwards since some documentas are embedded in drive some in OneDrive and some in icloud each with their particular synergies and legal bonds and trazability pathways i imagine?How can O unify all my profile data generation since lets say 2010 or can I go backwards when some were beta?Thank you very much for the time
Post not yet marked as solved
I am trying to restore some deleted files from my iCloud. Most are restoring and able to download. But the download is currently stuck and not progressing. If I stop the download, will I lose the ability to try and restore the files again? Or can I just stop the download and try again? I really do not want to lose these files in digital space!! I am terrified to stop the download. Has anyone had this issue?
Post not yet marked as solved
I've tried to load icloud image using phasset with options
requestOptions.isSynchronous = false requestOptions.isNetworkAccessAllowed = true
I get CloudPhotoLibraryErrorDomain Code=1005 error I don't understand where I make mistake, I have used SDWebImagePhotosPlugin methods as well as Photos methods like requestImageDataAndOrientation and requestImageData, still I get the image as nil and the above error
this is my code:
imageManager.requestImageDataAndOrientation(for: deviceImage, options: phImageRequestOptions()) { data,deliveryMode, orentation, _ in
if data != nil {
completion(data)
} else {
SDImageLoadersManager.shared.loaders = [SDWebImageDownloader.shared, SDImagePhotosLoader.shared]
SDWebImageManager.defaultImageLoader = SDImageLoadersManager.shared
let photosURL = NSURL.sd_URL(with: deviceImage)
SDImagePhotosLoader.shared.requestImage(with: photosURL as URL?, options: [.highPriority,.retryFailed,.refreshCached], context: [.customManager: self.manager], progress: nil) { image, data,error, success in
if image != nil {
completion(image?.pngData())
} else {
completion(nil)
}
}
}
Post not yet marked as solved
Latest Albums\Videos in iCloud not available from code until I open the Photos App.
Figured out that when I open the PHCollection picker and close it (even in a fraction of second), it triggers the iCloud sync on local Photos albums and I am able to get latest content.
Is there way to trigger the iCloud sync with Photos albums through program or at least a workaround like open\close the PHCollection picker in background?