OC直截了当的调用JS文件中的方法_LD

2018-09-27  本文已影响15人  LD_左岸

先说下碰见的问题

最终的做法是直接使用系统的 <JavaScriptCore/JavaScriptCore.h>库去搞

#import <JavaScriptCore/JavaScriptCore.h>
@property(nonatomic,strong)JSContext * context;
#pragma mark --- 返回des加密后的值
-(NSString*)returnDesValueWithStr:(NSString*)string
{
    NSString * str = [[NSBundle mainBundle]pathForResource:@"des" ofType:@"js"];
    NSString * jsStr = [NSString stringWithContentsOfFile:str];
    self.context = [[JSContext alloc] init];
    [self.context evaluateScript: jsStr];
    JSValue *addJS = self.context[@"strEnc"];
    JSValue *sum = [addJS callWithArguments:@[string,@"firstKey;",@"secondKey",@"threeKey"]];
    return [NSString stringWithFormat:@"%@",sum];
}
上一篇下一篇

猜你喜欢

热点阅读