【问题标题】:How do i delete a file in the xxxx.app directory如何删除 xxxx.app 目录中的文件
【发布时间】:2011-06-13 19:56:58
【问题描述】:

我有以下代码:

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! --");
}

输出:

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

当我运行程序时,它表明文件已被删除,见上文,但事实并非如此。当我检查时,使用“iPhone Explorer”文件仍然驻留在“xxxx.app”目录中,我猜这是应用程序的根目录。

如果有好心人能告诉我如何在我需要删除此文件时真正删除它,我将不胜感激。

【问题讨论】:

    标签: iphone objective-c nsfilemanager


    【解决方案1】:

    您无法删除应用程序包中的文件。 还有,

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

    输出“删除成功”,因为您在 fileExistsAtPath 时输出,即未删除时。

    【讨论】:

    • uhhhhhh 我真的很愚蠢,我已经看了这么长时间了:-(
    【解决方案2】:

    一旦 .app 捆绑包被签名并放置在设备上,您就无法从该捆绑包中添加或删除文件。

    【讨论】:

    • 你能推荐我应该怎么做,这样我才能摆脱这些文件吗?
    • 你为什么要删除文件?
    • 我认为这是个好主意,只是改变了策略,所以谢谢。
    猜你喜欢
    • 2015-01-20
    • 1970-01-01
    • 2016-06-07
    • 2021-02-19
    • 1970-01-01
    • 2015-12-26
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多