Objective-c - Packaged into .framework sdk. I want to put js files in it, but I don't want to use bundle. How can I read the js files?
过去多啦不再A梦
过去多啦不再A梦 2017-05-02 09:33:31
0
2
824

Used NSString * jsStr = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"xx" ofType:@"js"], and kept reporting Error Domain=NSCocoaErrorDomain Code=258 "The file name is invalid , does anyone know how to solve it?

过去多啦不再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