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?

4

3 回答 3

1

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

您可能忘记在 javascript 函数的参数中添加引号。
@"testPN(%@);"应该@"testPN('%@');".

于 2013-06-07T09:43:34.740 回答
0

看看这个维基:http ://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS

那有什么帮助吗?

于 2012-07-28T14:46:43.410 回答
0

@Suchi,如果您像下面这样使用self.webView,它将正常工作,

尝试这个...

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

[self.webView stringByEvaluatingJavaScriptFromString:jsStatement];
于 2013-10-28T13:17:18.240 回答