简体   繁体   English

fopen() 总是在 iOS 设备上返回 NULL

[英]fopen() always return NULL on iOS device

File exists in iOS bundle directory.文件存在于 iOS 捆绑目录中。 fopen() always return NULL on iOS device, but OK on iOS sumulator, codes as below: fopen()在 iOS 设备上总是返回NULL ,但在 iOS 求和器上正常,代码如下:

NSString *path = [NSBundle.mainBundle pathForResource:@"yuv420p_640x360" ofType:@"yuv"];
BOOL exists = [NSFileManager.defaultManager fileExistsAtPath:path];
NSLog(@"%d", exists); //prints "1"
const char *path2 = [path UTF8String];
FILE *fp = fopen(path2, "rb+"); //fp is NULL

Environment: macOS 12.0.1, M1 MacBook Pro, iPadOS 15.0环境:macOS 12.0.1、M1 MacBook Pro、iPadOS 15.0

The iOS execution environment is sandboxed, and you can not open a file in the bundle with "writing" mode, since the files in the bundle can not be modified (try with just "r" for the mode). iOS 执行环境是沙盒的,您无法使用“写入”模式打开包中的文件,因为无法修改包中的文件(尝试仅使用“r”模式)。

You cannot open any file in iOS.您无法打开 iOS 中的任何文件。 Apps are sandboxed in iOS ie An app can access only its directory and cannot access(read/write) any file outside its directory.应用程序在 iOS 中被沙盒化,即应用程序只能访问其目录,而不能访问(读/写)其目录之外的任何文件。

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

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