Using Javascript in iOS application

Last Updated: Jan 17, 2016 10:30PM PST

In order to use Apsalar in JavaScript code that is part of your iOS application, insert the following into webView:shouldStartLoadWithRequest:navigationType: in your UIWebViewDelegate file.

    if([[webView stringByEvaluatingJavaScriptFromString:@"typeof(Apsalar)"] isEqualToString:@"undefined"]) {
        // Inject Apsalar.JS in to the HTML
        [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Apsalar" ofType:@"js"] usedEncoding:nil error:nil]];
    } else if([Apsalar processJSRequest:webView withURL:request]) {
        // if processJSRequest handled this request it will return TRUE so
        // return NO (should not start load with request)
        return NO;


In your HTML code, import the Apsalar JS interface (Apsalar.js).

You can then use the following JS calls similar to those described above in your HTML/JS code in order to record events:

Apsalar.event(eventName, eventArgsObject)

where event is a string and eventArgsObject is a JS object with attribute:value pairs.

For example:

Apsalar.event('test', {a1:'bar', a2:'boo', a3:'baz'});

You CANNOT use calls to startSessionreStartSession, or endSession from JavaScript. These must be done from your Objective-C code (in your AppDelegate file) as described above.
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
Invalid characters found