Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting iCloud data doesn't clear out NSUbiquitousKeyValueStore?

I have an app that is configured to use iCloud. I am adding a key/value to the NSUbiquitousKeyValueStore and I can retrieve it as expected across all of my devices. However, if I delete my app's iCloud data from under Settings, I would expect that all of the iCloud data I added to NSUbiquitousKeyValueStore would be deleted as well, but this is not the case. I am able to retrieve all of the data, no matter how long I want for iCloud to sync.

I have gone to developer.icloud.com and watched as my other iCloud data (I am also using Core Data over iCloud) is deleted properly, but their is no folder where NSUbiquitousKeyValueStore keeps its data from what I can tell.

Does anyone know if this is supposed to be deleted? It seems kind of like a "Cloud memory leak" if the user can't delete this.

like image 657
lehn0058 Avatar asked Feb 19 '13 17:02

lehn0058


2 Answers

This is how I do it:

NSUbiquitousKeyValueStore *kvStore = [NSUbiquitousKeyValueStore defaultStore];
NSDictionary *kvd = [kvStore dictionaryRepresentation];
NSArray *arr = [kvd allKeys];
for (int i=0; i < arr.count; i++){
    NSString *key = [arr objectAtIndex:i];
    [kvStore removeObjectForKey:key];
}
like image 103
Mike M Avatar answered Oct 18 '22 00:10

Mike M


This will clear it out. #if DEBUG is to prevent you from accidentally shipping this code.

Swift 5.2

#if DEBUG
let allKeys = NSUbiquitousKeyValueStore.default.dictionaryRepresentation.keys
for key in allKeys {
    NSUbiquitousKeyValueStore.default.removeObject(forKey: key)
}
#endif
like image 3
Jayden Irwin Avatar answered Oct 18 '22 02:10

Jayden Irwin