简体   繁体   English

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

[英]The operation couldn’t be completed. Operation not permitted

Very strange problem with my iPhone App. 我的iPhone App非常奇怪的问题。 We have an App that has been approved and is in sales at the App Store. 我们有一个已经批准并在App Store销售的应用程序。 It contains a feature to download some database updates. 它包含下载某些数据库更新的功能。 The update comes in a ZIP via HTTP. 此更新通过HTTP以ZIP形式提供。 The problem is that I cannot save this downloaded ZIP because I get the "The operation couldn't be completed. Operation not permitted" error. 问题是我无法保存这个下载的ZIP,因为我得到“操作无法完成。操作不允许”错误。

BUT: this happens on 2 phones out of 10. If a phone cannot save the file it cannot do at all. 但是:这种情况发生在10个手机中。如果手机无法保存文件,则完全无法进行。 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. 但那些能够保存ZIP的手机总是有能力的。 All phones run the same iOS version and all of them are iPhone 4. This really drives me crazy. 所有手机都运行相同的iOS版本,所有手机都是iPhone 4.这真让我疯狂。

If I start XCode one phone gives no error in debug the other gives. 如果我启动XCode,一个手机在调试时没有给出错误,另一个给出。 And they always give. 他们总是给予。

Here is the code: 这是代码:

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

Any ideas, please? 请问有什么想法吗?

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: 根据您的目的,您可以编写各种地方:

  • If you want to store the file until you delete it, write to the documents directory: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] 如果要在删除文件之前存储该文件,请写入文档目录: [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] 如果您希望系统在设备空间不足时删除它(并且不关心在备份设备时是否保存它),请使用caches目录: [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() 如果您只是在处理它时暂时保存它并立即将其删除,请使用临时目录: NSTemporaryDirectory()

Also, BTW, it might be cleaner to use [directory stringByAppendingPathComponent:filename] rather than [NSString stringWithFormat:@"%@/%@", directory, filename] to construct paths. 另外,BTW,使用[directory stringByAppendingPathComponent:filename]而不是[NSString stringWithFormat:@"%@/%@", directory, filename]来构造路径可能更清晰。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 该操作无法完成。 (MKErrorDomain错误4) - The operation couldn’t be completed. (MKErrorDomain error 4) Xcode 4共享IPA“操作无法完成。 没有相应的文件和目录” - Xcode 4 share IPA “The operation couldn’t be completed. No such file or directory” “这项行动无法完成。 (可可错误512.)“ - “The operation couldn’t be completed. (Cocoa error 512.)” 该操作无法完成。 (可可错误1560.) - The operation couldn’t be completed. (Cocoa error 1560.) 该操作无法完成。 (com.facebook.sdk.login错误301。) - The operation couldn’t be completed. (com.facebook.sdk.login error 301.) Alamofire 错误:操作无法完成。 软件导致连接中止 - Alamofire Error: Operation couldn't be completed. Software caused connection abort didFailWithError:错误域= kCLErrorDomain代码= 0“无法完成操作。 (kCLErrorDomain错误0。)“ - didFailWithError: Error Domain=kCLErrorDomain Code=0 “The operation couldn’t be completed. (kCLErrorDomain error 0.)” 无法保存到数据存储:无法完成操作。 (可可错误133020.) - Failed to save to data store: The operation couldn’t be completed. (Cocoa error 133020.) CLLocationManager: allowDeferredLocationUpdates - 不断获取操作无法完成。 (kCLErrorDomain 错误 11。) - CLLocationManager: allowDeferredLocationUpdates - keep getting The operation couldn’t be completed. (kCLErrorDomain error 11.) phonegap代码:2消息:操作无法完成。 (kCLErrorDomain错误0。) - phonegap code: 2 message: The operation couldn’t be completed. (kCLErrorDomain error 0.)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM