该操作无法完成.不允许操作

Ted*_*ddy 6 iphone nsdata

我的iPhone App非常奇怪的问题.我们有一个已经批准并在App Store销售的应用程序.它包含下载某些数据库更新的功能.此更新通过HTTP以ZIP形式提供.问题是我无法保存这个下载的ZIP,因为我得到"操作无法完成.操作不允许"错误.

但是:这种情况发生在10个手机中.如果手机无法保存文件,则完全无法进行.如果我从商店重新下载应用程序,它不会更改它.但那些能够保存ZIP的手机总是有能力的.所有手机都运行相同的iOS版本,所有手机都是iPhone 4.这真让我疯狂.

如果我启动XCode,一个手机在调试时没有给出错误,另一个给出.他们总是给予.

这是代码:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[activeResponse release];
[theConnection release];

NSLog(@"%d", [receivedData length]);
NSString *s = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
NSLog(@"%@", s);
[s release];
[theRequest release];   
NSString *path = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"temp.zip"];
NSLog(path);
NSError * error;
if ([receivedData writeToFile:path options:NSDataWritingAtomic error:&error])
    NSLog(@"Success");
else 
    NSLog(@"Error");
if (error)
    NSLog([error description]);
Run Code Online (Sandbox Code Playgroud)

请问有什么想法吗?

Ano*_*mie 11

您不能写入应用程序包,我很惊讶它适用于您的任何设备.根据您的目的,您可以编写各种地方:

  • 如果要在删除文件之前存储该文件,请写入文档目录: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  • 如果要在系统空间不足的情况下允许系统删除它(并且不关心在备份设备时是否保存它),请使用caches目录: [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  • 如果您只是在处理它时暂时保存它并立即将其删除,请使用临时目录: NSTemporaryDirectory()

此外,顺便说一下,使用它[directory stringByAppendingPathComponent:filename]而不是[NSString stringWithFormat:@"%@/%@", directory, filename]构建路径可能更清晰.