Calling JavaScript function from iOS native function

766 views
Skip to first unread message

Rachit Arora

unread,
Jan 19, 2013, 2:05:55 AM1/19/13
to phonegap
I am building an app for iDyanmo Card Swipe Reader.
The problem with me is this i want to call javascript function from my
native code so as when card is swipe i can get to know and can do
changes in my HTML View or one can say HTML Page according to that. Or
suggest me a better approach for this except building the app in
native.I know how to call native function from javascript by iOS
plugin.
Please help me i am get stuck in this very badly.


Note: I want to call Javascript function from native function not vice-
versa.



Thanks & Regards
Rachit Arora

Shazron

unread,
Jan 19, 2013, 10:33:49 AM1/19/13
to phonegap
From your plugin:

NSString* result = [self.webView stringByEvaluatingJavaScriptFromString:@"myfunction('mystring')"];

Result is the result returned from the function.


Rachit Arora

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

To compile in the cloud, check out build.phonegap.com



Josh Arnold

unread,
Jan 21, 2013, 10:44:39 AM1/21/13
to phon...@googlegroups.com
Shazron, could you provide the correlating Android code to perform this same calling of a PhoneGap method from the native app?

Shazron

unread,
Jan 21, 2013, 3:02:27 PM1/21/13
to phonegap

Shazron

unread,
Jan 21, 2013, 3:03:27 PM1/21/13
to phonegap
Scratch that. If you dive into the code, at a certain point you will see how it writes to the webView, just trace the callbackContext.success call

Rachit Arora

unread,
Jan 22, 2013, 1:55:01 AM1/22/13
to phonegap
Thank you,i think it can help me alot.

Rachit Arora

unread,
Jan 23, 2013, 1:38:04 PM1/23/13
to phon...@googlegroups.com
Thanks for this can you please also tell me how to send parameter in this like nsstring *str=@"Hello";
How can i send str in this above function.

Thanks again

Rachit Arora

unread,
Jan 24, 2013, 6:34:31 AM1/24/13
to phon...@googlegroups.com
I am calling a function from AppDelegate of my HelloPlugin.m and over there I am calling [self.webView stringByEvaluatingJavaScriptFromString:@"myfunction('mystring')"]; it is not throwing any kind of error and on the same end it is also not calling my function...Please help...
Reply all
Reply to author
Forward
0 new messages