문제

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