Reputation: 7806
Is there any way to detect if the launch is from a iCloud backup? (restored)
I have looked here but there is nothing about it.
Their rules about what is allowed to backup is very strict(rejected multiple times for it) backing a database up, with just one user-generated change in it - now I have to back the data up somewhere else and reinsert it on restore from backup.
Upvotes: 18
Views: 2973
Reputation: 715
An approach would be to check if a file in the document dir with .isExcludedFromBackupKey
is present/valid, and create that file if it's not there at startup.
Files in the document dir with that flag are removed when a backup is restored.
var resourceURL = documentFileURL
var resourceValues = URLResourceValues()
resourceValues.isExcludedFromBackup = excludedFromBackup
try resourceURL.setResourceValues(resourceValues)
Upvotes: 0
Reputation: 226
https://developer.apple.com/documentation/security/ksecattraccessiblealwaysthisdeviceonly
Keychain items can be marked as not to be backed up by using one of the accessible attribute with “ThisDeviceOnly”.
You could write a flag to NSUserDefaults and Keychain (Using kSecAttrAccessibleAlwaysThisDeviceOnly), whenever the keychain item is missing but the user defaults value is present (or a backed up keychain item) then it must have been restored from backup. Be aware of secure and not secure iTunes backups as a scenario too. Insecure backups shouldn’t have any keychain items.
Upvotes: 4