操作无法完成。不允许操作 [英] The operation couldn’t be completed. Operation not permitted

查看:154
本文介绍了操作无法完成。不允许操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Very strange problem with my iPhone App. We have an App that has been approved and is in sales at the App Store. It contains a feature to download some database updates. The update comes in a ZIP via HTTP. The problem is that I cannot save this downloaded ZIP because I get the "The operation couldn’t be completed. Operation not permitted" error.

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

BUT: this happens on 2 phones out of 10. If a phone cannot save the file it cannot do at all. If I redownload the app from the store it does not change it. But those phones who are capable to save the ZIP are always capable. All phones run the same iOS version and all of them are iPhone 4. This really drives me crazy.

如果我启动XCode,一部手机在调试中没有出错,其他手机给出。他们总是给。

If I start XCode one phone gives no error in debug the other gives. And they always give.

以下是代码:

- (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]);

请问任何想法?

推荐答案

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

You are not allowed to write to the application bundle, I'm surprised it works on any of your devices. There are various places you can write, depending on what your purpose is:


  • 如果要保存文件直到删除它,请写到文档目录: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0]

  • 如果要允许系统如果设备空间不足(并且不关心设备备份时是否保存),请删除它,使用缓存目录: [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)objectAtIndex: 0]

  • 如果您只是在处理它时暂时保存它并立即将其删除,请使用临时目录: NSTemporaryDirectory()

  • If you want to store the file until you delete it, write to the documents directory: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  • If you want to allow the system to delete it if the device is running low on space (and don't care if it is saved when the device is backed up), use the caches directory: [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  • If you're just saving it temporarily while you process it and will delete it right away, use the temporary directory: NSTemporaryDirectory()

另外,BTW,使用 [可能更干净]目录stringByAppendingPathComponent:filename] 而不是 [NSString stringWithFormat:@%@ /%@,目录,文件名] 构建路径。

Also, BTW, it might be cleaner to use [directory stringByAppendingPathComponent:filename] rather than [NSString stringWithFormat:@"%@/%@", directory, filename] to construct paths.

这篇关于操作无法完成。不允许操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆