开发者

How do i delete a file in the xxxx.app directory

I have the following code:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"txt"];

if([fileManager fileExistsAtPath:path1]) {
    NSLog(@"-- sample file found --");


    AccessQuestionsDB *accessQuestionDataFunction = [AccessQuestionsDB new];
    idCounter = [accessQuestionDataFunction populateTheDatabase: path1 theID:0 firstTime: YES];

    [accessQuestionDataFunction release];

    [fileManager removeItemAtPath:path1 error:NULL];

    if ([fileManager fileExistsAtPath:path1]) {
        NSLog (@"Remove %@ successful", path1);
    } else {
        NSLog (@"Remove %@ failed", path1);
    }

}
else {
    NSLog(@"-- NO SAMPLE FILE! --");
}

Output:

2011-06-13 21:41:04.471 xxxx[1726:707] Remove /var/mobile/Applications/B1CC3E09-2A1D-4CD7-976D-E190A238EC79/xxxx.app/myFile.txt successful

When i run the program it indicate that the file is deleted, see above, but it is not. When i check, using "iPhone Explorer" the files still resides in the "xxxx.app" directory, which i guess 开发者_如何学运维is the root directory for the application.

I would really appreciate if someone nice could show me how to really delete this file as i need it removed.


You can't delete files in the app bundle. Also,

if ([fileManager fileExistsAtPath:path1]) {
    NSLog (@"Remove %@ successful", path1);
} else {
    NSLog (@"Remove %@ failed", path1);
}

outputs "Remove successful" because you output that when fileExistsAtPath, i.e. when it was not deleted.


You can not add or remove files from the .app bundle once it has been signed and placed on the device.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜