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);
来者即是缘份,请帮忙点个赞吧~
网友评论