檔案存在于 iOS 包目錄中。fopen()總是NULL在iOS設備上回傳,但在iOS sumulator上可以,代碼如下:
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
環境:macOS 12.0.1、M1 MacBook Pro、iPadOS 15.0
uj5u.com熱心網友回復:
iOS 執行環境是沙盒的,您不能使用“寫入”模式打開包中的檔案,因為包中的檔案無法修改(嘗試只使用“r”模式)。
uj5u.com熱心網友回復:
您無法在 iOS 中打開任何檔案。應用程式在 iOS 中被沙箱化,即應用程式只能訪問其目錄,而不能訪問(讀/寫)其目錄外的任何檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/382407.html
上一篇:View元素上的事件偵聽器
