Home > Blockchain >  fopen() always return NULL on iOS device
fopen() always return NULL on iOS device

Time:12-14

File exists in iOS bundle directory. fopen() always return NULL on iOS device, but OK on iOS sumulator, codes as below:

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

CodePudding user response:

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).

CodePudding user response:

You cannot open any file in iOS. Apps are sandboxed in iOS i.e. An app can access only its directory and cannot access(read/write) any file outside its directory.

  • Related