objective-c - 打包成.framework sdk 想在里面放 js 文件,不想用 bundle,怎么可以读取到 js 文件
过去多啦不再A梦
过去多啦不再A梦 2017-05-02 09:33:31
0
2
797

用了 NSString * jsStr = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"xx" ofType:@"js"] ,一直报 Error Domain=NSCocoaErrorDomain Code=258 "The file name is invalid ,有没有知道怎么解决的?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
迷茫

Static libraries don’t seem to work, you must create bundles, and the js files in the bundle will be automatically converted into .txt files by the system. A better solution is to compress the js code and then perform URLEncode encoding to solve this problem.

给我你的怀抱

You can package the files you need together into Framework 里面,然后通过 NSBundle 去获取这个文件。不同的是不能使用 mainBundle,因为此时的 mainBundle 指的引用 Framework this program. Of course your JS file cannot be found.

Solution:

  1. File in Framework 的工程里面,Target->Build Phases->Copy Bundle Resources 里面加入你需要打包进 Framework

  2. Use when you need to read a file

NSBundle *bundle = [NSBundle bundleWithIdentifier:@"your.framework.id"];
if (bundle) {
    NSString *filePath = [bundle pathForResource:@"somefile" ofType:@"js"];
    // ...
}

PS: Framework It needs to be a dynamic library!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template