How do I call an Objective-C method from Javascript in UIWebView?

By : gnfti

I'm developing a native iPhone app using Phonegap, so everything is done in HTML and JS. I am using the Flurry SDK for analytics and want to use the

[FlurryAPI logEvent:@"EVENT_NAME"];

method to track events. Is there a way to do this in Javascript? So when tracking a link I would imagine using something like

<a onClick="flurryTrackEvent("Click_Rainbows")" href="#Rainbows">Rainbows</a>
<a onClick="flurryTrackEvent("Click_Unicorns")" href="#Unicorns">Unicorns</a>

"FlurryAPI.h" has the following:

@interface FlurryAPI : NSObject {

+ (void)startSession:(NSString *)apiKey;
+ (void)logEvent:(NSString *)eventName;
+ (void)logEvent:(NSString *)eventName withParameters:(NSDictionary *)parameters;
+ (void)logError:(NSString *)errorID message:(NSString *)message exception:(NSException *)exception;

+ (void)setUserID:(NSString *)userID;
+ (void)setEventLoggingEnabled:(BOOL)value;
+ (void)setServerURL:(NSString *)url;
+ (void)setSessionReportsOnCloseEnabled:(BOOL)sendSessionReportsOnClose;


I'm only interested in the logEvent method(s). If it's not clear by now, I'm comfortable with JS but a recovering Obj-C noob. I've read the Apple docs but the examples described there are all for newly declared methods and I imagine this could be simpler to implement because the Obj-C method(s) are already defined.

Thank you in advance for any input.

By : gnfti


PhoneGap has functionality for adding native plugins, to add a Flurry log event plugin for iOS I would do something like this:

Add a PGFlurry PhoneGap plugin class:



You can find the Phonegap Flurry Plugin written by me at

By : Kamal J

Don't use their objective-c library, use their js library and you won't have to worry about objective-c. :)

By : pfrank

This video can help you solving your question :)
By: admin