Вопрос

When testing my app from Xcode, in the iOS simulator I can select "Reset content and settings" so that the app can start with a clean slate. I'm mostly interested in wiping out the stored core data.

How do I achieve the same thing when I run the app on an actual iPad from Xcode (through USB)? I don't want to change the actual app for this to do it programmatically, because I don't plan to release a reset option within the app.

Thanks in advance.

Это было полезно?

Решение

It is enough, if you delete the app from your iPad. All content, which was created by your application will be removed as well.

But if you change your mind and plan to do it programmatically, this might help you:

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];


NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSArray *contents = [fileManager contentsOfDirectoryAtPath:documentsDirectory error:NULL];
NSEnumerator *e = [contents objectEnumerator];
NSString *filename;
while ((filename = [e nextObject])) { 
        [fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:filename] error:NULL];
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top