1

I have an html file in the resource bundle that is displayed in a webview. There are links on the html page that access a website on the net. I want to check reachability each time a link is touched on the html page. How can I do this?

The iOS sample code for Reachability has a test for an html page directly. How do I detect when a link is touched on an html page. I am guessing this has something to do with setting the notification but I'm not sure how to do it.

Krease
  • 15,805
  • 8
  • 54
  • 86
LarryB
  • 101
  • 1
  • 3

2 Answers2

0

The <UIWebViewDelegate> method webView:shouldStartLoadWithRequest:navigationType: will help you out. Implement it in your delegate, and perform your reachability test there, returning YES or NO as appropriate.

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"loading %@", request);
    return YES;
}
Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • I have done this and the initial page in the bundle produces the same "no connection" error as a page on the web. I want the first page NOT to check internet status and display from bundle. Then I want to turn on the reachability testing. I have not figured out how to bypass the shouldStartLoadWithRequest for the first page from the bundle. – LarryB Mar 30 '13 at 18:50
0

Use this javascript function in HTML to know reachablity

function CheckOnlineStatus()
    {
        var returnValue = false;
        
        // do your thing!function checkConnection() {
        var networkState = navigator.network.connection.type;
        
        var states = {};
        states[Connection.UNKNOWN]  = 'offLine';
        states[Connection.ETHERNET] = 'Ethernet connection';
        states[Connection.WIFI]     = 'WiFi connection';
        states[Connection.CELL_2G]  = 'Cell 2G connection';//Cell 2G connection
        states[Connection.CELL_3G]  = 'Cell 3G connection';//Cell 3G connection
        states[Connection.CELL_4G]  = 'Cell 4G connection';//Cell 4G connection
        states[Connection.NONE]     = 'offLine';
        
        
        if(states[networkState] != 'offLine')
        {
            returnValue = true;
        }
        
        return returnValue;
    }
Vinodh
  • 5,262
  • 4
  • 38
  • 68
  • How do you get this value into iOS for testing purposes? – LarryB Mar 30 '13 at 18:45
  • http://stackoverflow.com/questions/15537320/invoke-method-in-objective-c-code-from-html-code-using-uiwebview/15541607#15541607 pleace us the this link to acheive that – Vinodh Apr 01 '13 at 03:45