iOS 调用本地资源 js文件里的方法

2023-04-05  本文已影响0人  超人_22

1、导入头文件

#import <JavaScriptCore/JavaScriptCore.h>

2、获取本地bundle js 文件

 NSString *scriptPath = [[NSBundle mainBundle] pathForResource:@"common" ofType:@"js"];
    NSString *scriptString = [NSString stringWithContentsOfFile:scriptPath encoding:NSUTF8StringEncoding error:nil];
    JSContext *context = [[JSContext alloc] init];
    [context evaluateScript:scriptString];
    //调用js 方法
    JSValue *function = context[@"uc_authcode"];
    //传参->返回token
    JSValue *token = [function callWithArguments:@[@"ayqCtCTXtacYzpiu",@"ENCODE",@"cQnGW9Qmhqq5Qhq9"]];
    LOG(@"token = %@",token);

来者即是缘份,请帮忙点个赞吧~

上一篇 下一篇

猜你喜欢

热点阅读