3

I have a js method testPN(param), which I need to call from my native app. I am using these lines to achieve that -

NSString *jsStatement = [NSString stringWithFormat:@"testPN(%@);", custData];
[self writeJavascript:jsStatement];

This somehow does not work. If I change to testPN() without any argument and call it like this it works -

NSString *jsStatement = [NSString stringWithFormat:@"testPN();"];
[self writeJavascript:jsStatement];

custData is just a regular non-null NSString* Any idea as to what I could be doing wrong?

5
  • Do you mean the javascript call doesn't occur, or it does actually occur but it is not successful? Commented Jun 7, 2012 at 20:22
  • i believe it doesn't even get to the function :-( Commented Jun 7, 2012 at 20:28
  • What does writeJavascript look like? Have you tried putting an alert as the first line in the testPN() function to a) check the javescript function is being called, b) check its being called with the arguments you expect? Then if it is c) add an alert at the end of the function and see if its reached, if not then the contents of custData are causing your javascript function to malfunction. Commented Jun 7, 2012 at 20:32
  • writeJavascript is a Cordova function in CDVPlugin.h. I tried putting an alert as the first statement and found that it is never being called. Any idea why? Commented Jun 7, 2012 at 20:36
  • Sorry I'm not intimately familiar with Cordova. But I'm very familiar with the technique PhoneGap uses to call Javascript from Objective-C. So if you get no answers after a while, I presume CDVPlugin.h is open source and available for examination so its internal mechanism could be examined if you could direct me to where to get it. But wait firs see if anybody knows the reason. Commented Jun 7, 2012 at 20:43

3 Answers 3

1

NSString *jsStatement = [NSString stringWithFormat:@"testPN(%@);", custData];

You have probably forgotten to add quotes in you javascript function's parameters.
@"testPN(%@);" should be @"testPN('%@');".

Sign up to request clarification or add additional context in comments.

Comments

0

Take a look at this wiki: http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS

Could that be of any help?

Comments

0

@Suchi, if you use self.webView like below, it will work properly,

Try this...

NSString *jsStatement = [NSString stringWithFormat:@"testPN(%@);", custData];

[self.webView stringByEvaluatingJavaScriptFromString:jsStatement];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.