简体   繁体   English

Cocoa:iOS:fopen有时失败并出现错误:“操作不允许”

[英]Cocoa: iOS: fopen fails sometimes with error: “Operation not permitted”

I have a very weird behaviour in which I sometimes get a "Operation not permitted" error when using fopen in my code, and sometimes everything runs smoothly. 我有一个非常奇怪的行为,当我在我的代码中使用fopen时,我有时会遇到“不允许操作”错误,有时一切运行顺利。

My first thought was a sandbox issue, but in both cases I write the files to the same location. 我的第一个想法是沙盒问题,但在这两种情况下我都将文件写入同一位置。 I run only up to 4 fopens before I fclose them, so I don't believe I maxed-out my files descriptors. 在我关闭它之前,我只运行了4个fopens,所以我不相信我最大化了我的文件描述符。 The next batch of files will always run after the 4 previous ones were fclosed. 下一批文件将在之前的4个文件被删除后始终运行。

I'm out of ideas how to approach this ambiguous behaviour, and would love to hear what you have in mind. 我没有想法如何处理这种模棱两可的行为,并且很想听听你的想法。

Thanks, 谢谢,

Nili 尼莉

May be related to data protection caused by Passcode set on the Device's Settings. 可能与设备设置中设置的密码导致的数据保护有关。 If the fopen is called when the device was locked and passcode is needed, "Operation not permitted" will be returned. 如果在设备被锁定并且需要密码时调用fopen,则将返回“不允许操作”。

Use these events in AppDelegate to identify this scenario and stop/start file manipulation: 在AppDelegate中使用这些事件来识别此方案并停止/启动文件操作:

- (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application;
- (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application;

See also: UIApplicationDelegate documentation 另请参见: UIApplicationDelegate文档

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM