Call javascript from objective-c, only works with system functions like alert() etc / phonegap

Posted by adrian on Stack Overflow See other posts from Stack Overflow or by adrian
Published on 2010-05-21T12:45:29Z Indexed on 2010/05/21 12:50 UTC
Read the original article Hit count: 453

hi havent found the solution yet in the forum.

i want to call a function i created in the index.html via a objective-c function. As explained in stringByEvaluatingJavaScriptFromString

so the network detection doesnt work for me

the function gets called but no javascript is called in the index.html here is the code i use

- (void)updateReachability:(NSString*)callback
{
    NSString* jsCallback = @"navigator.network.updateReachability";
    if (callback)
        jsCallback = callback;

    NSString* status = [[NSString alloc] initWithFormat:@"%@({ hostName: '%@', ipAddress: '%@', remoteHostStatus: %d, internetConnectionStatus: %d, localWiFiConnectionStatus: %d  });", 
                        jsCallback,
                        [[Reachability sharedReachability] hostName],
                        [[Reachability sharedReachability] address],
                       [[Reachability sharedReachability] remoteHostStatus],
                       [[Reachability sharedReachability] internetConnectionStatus],
                       [[Reachability sharedReachability] localWiFiConnectionStatus]];


    [webView stringByEvaluatingJavaScriptFromString:status];
    [status release];
}

If i log the status the string i see can be executed in the index.html file, the syntax is ok. but it doesnt get called

if i do alert( etc... it gets called...

need some help pls, because network detection is a kill criteria to publish a app!!!

Adrian

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about objective-c