Wednesday, October 9, 2013

calling javascript objective-c without visible uiwebview

I want to call javascript functions from my objective-c. This for iphone. I understand how the call to the javascript function is done with this line

NSString *returnValue = [webView stringByEvaluatingJavascriptFromString:method];

But I dont actually want a webview to be seen or used as part of the UI. So can I just create an instance of it right before calling the method above in some way.

I have tried:

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectZero];[webView loadRequest:[NSUrLRequest requestWithUrl:url]];

but nothing seems to happen. So is there a method similar to the above that I am meant to use.

add the webview in your controller’s view in order to run the javascript. it won’t be visible since it has zero height & width.

No comments:

Post a Comment