0

I am integrating a framework into my project. However, I am having troubles in referring to files under its Resources folder.

The code should be:

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 !!!

Since I cannot refer to abc.json under SomeFramework.framework/Resources folder, filePath is always nil, leading to the app crashed at 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

In Finder, I checked SomeFramework.framework. It does have Resources folder, under which sadly I cannot find out how to refer to its files.

Is there some actions that I missed in order to refer to files under Resources folder of SomeFramework.framework?

Please show me how.

(I am developing in XCode 6)

Thanks, everyone

quanguyen
  • 1,443
  • 3
  • 17
  • 29

1 Answers1

0

Thank to this link IOS Static Framework with resources inside, I found out how to fix my problem: Going to Build Phase/Copy Bundle Resources and add SomeFramework.framework.

As expected, after adding SomeFramework.framework, the app now can refer to resources under SomeFramework.framework and thus works beautifully.

Regards,

Community
  • 1
  • 1
quanguyen
  • 1,443
  • 3
  • 17
  • 29