Latest 0.1.0
Homepage https://github.com/Lukas-Stuehrk/WindowTimers
License MIT
Platforms ios 7.0, requires ARC
Frameworks JavaScriptCore
Authors

WTWindowTimers

In iOS 7, Apple introduced the possibility to [execute JavaScript via the JavaScriptCore JavaScript
engine] (http://nshipster.com/javascriptcore/). Unfortunately, JavaScriptCore is missing some
objects and functions a JavaScript environment of a browser would have. Especially the methods
described in the [WTWindowTimers specification]
(https://html.spec.whatwg.org/multipage/webappapis.html#windowtimers), such as setTimeout or
setInterval are not provided. This library implements those methods, so it is possible to use
JavaScript libraries which were originally developed for in-browser use in your Objective-C
(or Swift) application without the need to use a hidden WebView.

Provided functions

This library tries to implement the full specification fo the Window Timers, including passing a
string as first argument to setTimeout or setInterval or passing additional arguments to both
mentioned functions.

How to use it

Create a new instance of the WTWindowTimers class. Then call the extend: method and pass either
a JSContext instance or a JSValue instance. The given object will be extend with the functions.

#import <WindowTimers/WindowTimers.h>

...

JSContext *jsContext = [JSContext new];

WTWindowTimers *timers = [WTWindowTimers new];
[timers extend:jsContext];

// Now jsContext has the additional functions setTimeout, clearTimeout, setInterval, clearInterval
jsContext[@"callCounter"] = @0;
[jsContext evaluateScript:@"setTimeout(function(){callCounter += 1;}, 1000);"];

// Run the main loop for at least 1.1 seconds so we make sure that the callback is executed.
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.2]];
NSLog(@"callCounter is %@", jsContext[@"callCounter"]); // Will log 1.

Latest podspec

{
    "name": "WindowTimers",
    "version": "0.1.0",
    "summary": "An implementation of the JavaScript WindowTimers to extend JavaScriptCore.",
    "description": "                        In iOS 7, Apple introduced the possibility to [execute JavaScript via the JavaScriptCore JavaScript engine]n                        (http://nshipster.com/javascriptcore/). Unfortunately, JavaScriptCore is missing some objects and functions a browsern                        JavaScript environment would have. Especially the methods described in the [WindowTimers specification]n                        (https://html.spec.whatwg.org/multipage/webappapis.html#windowtimers), such as `setTimeout` or `setInterval` are notn                        provided. This library implements those methods, so it is possible to use JavaScript libraries which were originallyn                        developed for in-browser use in your Objective-C (or Swift) application without the need to use a hidden WebView.n",
    "homepage": "https://github.com/Lukas-Stuehrk/WindowTimers",
    "license": "MIT",
    "authors": {
        "Lukas Stu00fchrk": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Lukas-Stuehrk/WindowTimers.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "WindowTimers/WindowTimers.*",
    "resource_bundles": {},
    "public_header_files": "WindowTimers/WindowTimers.h",
    "frameworks": "JavaScriptCore"
}

Pin It on Pinterest

Share This