美文网首页
iOS 调用本地资源 js文件里的方法

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

作者: 超人_22 | 来源:发表于2023-04-05 16:46 被阅读0次

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);

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

相关文章

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/ppzeddtx.html