2014-12-06 37 views
0

我正在將框架集成到我的項目中。但是,我在參考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.jsonSomeFramework.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

請告訴我如何。

謝謝大家

回答

0

感謝這個鏈接IOS Static Framework with resources inside(我在XCode中6開發),我發現瞭如何解決我的問題:要Build Phase/Copy Bundle Resources,並添加SomeFramework.framework。

正如預期的那樣,在添加SomeFramework.framework後,該應用程序現在可以參考SomeFramework.framework下的資源,因此可以很好地工作。

Regards,