Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 810 Bytes

README.md

File metadata and controls

25 lines (18 loc) · 810 Bytes

JSContext 支持window.setTimeout

参考1:https://developer.mozilla.org/en-US/docs/Web/API/setTimeout

参考2:https://developer.mozilla.org/en-US/docs/Web/API/setInterval

JavaScript 调用参考

nativeLog("开始计时");
var intervalId = setInterval(function(){nativeLog("客户端完成计时 setInterval 任务");}, 1000);
nativeLog(intervalId);
setTimeout(function(){nativeLog("客户端完成计时任务");clearInterval(intervalId);}, 3000);

Objective - C 参考

JSContext *ctx = [[JSContext alloc] init];
[ctx enableWindowTimer];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"js"];
NSString *script = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[ctx evaluateScript:script];