Programmatically checking when the last iCloud backup date was - ios

Is it possible to check if the /Documents directory in an iOS app have been recently backed up, or if ever at all?
Is this doable without putting explicit support on iCloud?
My app simply stores random stuff in the /Documents directory without ever worrying about any iCloud specific functionality or Apple API. Seems like the app data iCloud backup still covers the /Documents folder, but it would be nice to be able to tell or warn the user if their data hasn't been backed up to iCloud for a while, especially with important app data.

Related

iOS iCloud documents: can I prevent documents from being purged?

I have an app that stores documents in iCloud. iOS seems to regularly purge the local copies of the ubiquitous documents, forcing my users to re-download from iCloud. I had assumed this was due to low storage on the devices but I’ve experienced it myself when my device has more than 3GB of free space.
I also see the same behaviour in the Apple Books app. On the other hand in the Apple TV app on the same device, purchased movies I download don’t ever seem to be automatically purged. This has been the case for me since around the launch of iOS 13, but some of my users have complained of the issue on earlier iOS versions.
Is there a flag I’m missing somewhere that would prevent iOS from purging my documents? The biggest these files get is around 5MB.
Edit based on following Warren Burton's link: After reading the document at https://developer.apple.com/icloud/documentation/data-storage/ , I'm wondering if what I'm looking for is the "do not back up" attribute. I'd previously interpreted this as meaning that if a user reinstalled from a backup, all my app's documents would be lost. But if documents are stored in iCloud, I suppose they would still be available in the same way after a backup is restored, so they don't actually need to be in the user's backup? To further add to my confusion, the docs at https://developer.apple.com/documentation/foundation/urlresourcekey/1408756-isexcludedfrombackupkey specifically say not to use this attribute on user documents, so maybe this isn't the right attribute. Can anyone clarify?
I’ve come to the conclusion that there’s no way to get the behaviour I want by just relying on the iCloud file management itself.
What I’m going to attempt to do is to copy files manually from the ubiquity container to the local documents and work with them there, saving back to the ubiquity container as necessary. It seems a bit inelegant but should get the experience I want.

Realm Swift: Is it possible to keep database after the apps is uninstalled?

Using realm swift, is it possible to keep and maintain the realm database file of the apps in device memory even after the apps is uninstalled from the device?
Thank you very much for any help.
Sadly not. This is a limitation of iOS more than a limitation of Realm. When an iOS app is uninstalled from a device, all of the files associated with it are deleted (including any Realm files).
If you want file data to persist even after the app is deleted, you'll need to look at a cloud hosting solution to hang onto a copy of those files. In this case, the easiest one would most likely be CloudKit.
Applications all files are leftover when deleting an app. iOS apps are Sandboxed. This means that each App has its own space in disk, with its own directories, which act as the home for the app and its data.
Deleting an app from the iPhone deletes this sandbox, deleting all data associated with the app.

Will my app be again rejected if still stores a small amount of data on iCloud after I flagged everything not to be backed up?

I'm having an iOS app that moves files from Resources to NSDocumentDirectory and then I download from my server more files and put them there. My app was rejected because it stored 15mb on iCloud and I put that flag (That says that I do not want those files to be backed up on iCloud) on files after writing them to phone but my problem is that it still stores me 91.3kb.
I even putted that flag on whole App DocumentDirectory. But same result.
Will my app be rejected for that stored stuff?
How can i see what data is there?
No , it wont be rejected for that , I had the same situation where I wanted users to have ability to backup their database , but AppStore complained about it , then I removed only database file from iCloud backup and my app was accepted by AppStore ,
this "additional" data might be NSUserDefaults or some configuration/cache file.

IOS: Data persistence between versions of the app

I cannot find any information on topic: what is happening when I release new version of iOS application on iTunes? Is older version on device completely replaced? Or there is a persistence of Documents folder?
Is it possible to make update to be like a "clean" installation?
When you release an update to your iOS app and the user installs it, the system does not wipe out any data from within the app.
This means that data in a given user's Documents directory, NSUserDefaults, as well as the keychain will persist between app updates.
A couple of important notes, however:
The Caches directory of an app is never reliably persisted, so if you want to make sure data stays safe, don't put it in this directory
Items in the keychain seem to persist even if you completely erase the app and re-install it. I've noticed this in the past, so it may be a good thing to keep in mind
In short, if you want data cleaned out of your app on each update (not sure why you would), you'll have to do so manually.
Your Documents folder will not be cleaned.
If you want to clear it, make sure to do it programmatically in your new release.
The Documents folder is deleted only when the user deletes the app.

Error turning off iCloud for Core Data on iOS7

My project has a really ugly iCloud implementation in production today and I was planning to disable it for my next update (we don't need iCloud). Here is the approach I am taking to migrate users off of iCloud and onto a local store - the update has the iCloud entitlement removed from the app and this simple sequence of events is initiated at app launch:
If there is an iCloud store ( [[NSFileManager defaultManager] fileExistsAtPath:[legacyStoreUrl path]]
load the "legacy" iCloud store
Migrate the iCloud store to local store
([_persistentStoreCoordinator migratePersistentStore:legacyStore toURL:targetStoreUrl options:options withType:NSSQLiteStoreType error:&legacyStoreMigrationError]);
delete the legacy store
([fileManager removeItemAtURL:legacyStoreUrl error:&legacyStoreRemovalError])
Else
load (or create) the local store
This all works great - on iOS6.
When I run the same code on iOS7 to migrate the local store it appears not to find the iCloud store. I don't get any indication of error, the call to the FileManager to ask if the store is there simply returns false. I verified that the url for the store used by the upgraded app is exactly the same as the one used in the previous version. Also note that the existing version of the app runs on iOS7 without any trouble accessing iCloud store.
Any thoughts on why this might be or maybe some leads on what else to investigate?
It's happening because you removed the iCloud entitlement. Without that, you're not permitted to access the iCloud store, so the whole scheme falls apart. If this works on iOS 6, it's a bug, because you're really not supposed to get access to anything iCloud-related without the correct entitlements. With iOS 7 there are a ton of internal changes, so it's not surprising they found and fixed that.
So you'll need to put that entitlement back.
Two other details:
When you do the migration, make sure to set the new NSPersistentStoreRemoveUbiquitousMetadataOption to #YES in the options dictionary. Otherwise some cloud-related metadata will stick around, and that can really ruin your day later on. (You might already know this but since you didn't mention it I thought I would).
When you remove the cloud store, don't use that NSFileManager call. For one thing, it misses the SQLite wal and shm files. Worse than that though, it leaves all the existing iCloud transaction logs just sitting there taking up space. You'll want the new(ish) removeUbiquitousContentAndPersistentStoreAtURL:options:error method on NSPersistentStore. The options dictionary here should include the same cloud-related keys you'd use when adding an iCloud store, because that's necessary to find the transaction logs.

Resources