Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  16] [ 5]  / answers: 1 / hits: 17404  / 13 Years ago, mon, october 10, 2011, 12:00:00

I'm hoping to be able to use PhoneGap for my app. I will have to build a custom protocol/plugin so that I can call Native methods from the Javascript. I know you can call a success function in the Javascript when the native code returns.



What I need to be able to do is call a javascript function from the native code. Basically the app will connect to an OSX companion app over local network and when the OSX app send data to the iOS app it is processed in an Objective C method, I need to be able to send the result into the PhoneGap/javascript and do something with it in the WebView.



Is this possible? I have only been able to find information about calling native from javascript not the other way around.



Thanks,
Thomas



Using the code from Answer below here:



MyPhoneGapPlugin.m



- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
NSLog(@Connected To %@:%i., host, port);

NSString* jsString = [NSString stringWithFormat:@alert(connected to: %@);, host];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];

[self readWithTag:2];
}


Giving me the error 'Unknown receiver 'theWebView' did you mean 'UIWebView'?



UPDATE: Found the answer: using the phonegap helper I can write something like this...



    [super writeJavascript:@alert('connected');];

More From » objective-c

 Answers
78

Found the PhoneGap helper to accomplish this... Write javascript to the webView using:



    [super writeJavascript:@alert('it works');];

[#89687] Sunday, October 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gavenmekhio

Total Points: 732
Total Questions: 89
Total Answers: 93

Location: Central African Republic
Member since Mon, Aug 10, 2020
4 Years ago
;