我正在將框架集成到我的項目中。但是,我在參考Resources
文件夾下的文件時遇到麻煩。請參閱框架的資源文件夾下的文件
的代碼應該是:
NSString *frameworkPath = @"SomeFramework.framework/Resources/abc";
NSString *filePath = [[NSBundle mainBundle] pathForResource:frameworkPath ofType:@"json"]; // always nil !!!
// Load the file into an NSData object called JSONData
NSError *error = nil;
NSData *JSONData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error]; // crashed here !!!
既然不能指abc.json
SomeFramework.framework/Resources
文件夾下,filePath
總是nil
,導致應用程序崩潰的JSONData
:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSPlaceholderData initWithContentsOfFile:options:error:]: nil file argument'
*** First throw call stack:
(0x2435c49f 0x31b52c8b 0x2435c3e5 0x24fc3f3b 0x24fc3ecd 0x345fd 0x323e9 0x32021 0x27307 0x20d99 0x1a19b 0x24036369 0x240363b9 0x240364fd 0x240342b7 0x24030675 0x2403b357 0x1ae9db 0x1ae9c7 0x1b6e29 0x1b12c9 0x1b221f 0x243223b1 0x24320ab1 0x2426e3c1 0x2426e1d3 0x2b66c0a9 0x2787dfa1 0x22d79 0x320d2aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
在Finder
,我檢查SomeFramework.framework
。它確實有Resources
文件夾,在這個文件夾下,可惜我找不到如何引用它的文件。
是否有一些操作,我錯過了,以便參考Resources
文件夾中的文件SomeFramework.framework
?
請告訴我如何。
謝謝大家