The operation could not be completed. operation not allowed

A very strange problem with my iPhone App. We have an app that has been approved and sold on the App Store. It contains the function of downloading some database updates. Updating occurs through ZIP through HTTP. The problem is that I cannot save this downloaded ZIP, because I get the message "The operation could not be completed. The operation error was not resolved."

BUT: this happens on 2 phones out of 10. If the phone cannot save the file, it cannot do this at all. If I restart the application from the store, it will not change it. But those phones that are capable of saving ZIP are always capable. All phones work with the same version of iOS, and all of them are iPhone 4. It really drives me crazy.

If I run Xcode, one phone does not give errors in debugging, which gives another. 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?

+6
source share
1 answer

You are not allowed to write to the application package, I am surprised that it works on any of your devices. There are various places that you can write, depending on your purpose:

  • If you want to save the file before deleting it, write to the document directory: [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  • If you want the system to delete it if the device is running at a low level (and it doesn’t matter if it was saved when backing up the device), use the caches directory: [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  • If you temporarily save it while it is being processed and delete it immediately, use the temporary directory: NSTemporaryDirectory()

Furthermore, BTW, it might be easier to use [directory stringByAppendingPathComponent:filename] instead of [NSString stringWithFormat:@"%@/%@", directory, filename] to create paths.

+10
source

Source: https://habr.com/ru/post/885532/


All Articles