Use cell connection if Wifi not available in iOS.

Discussion in 'iOS Programming' started by RookieAppler, Jan 28, 2013.

  1. RookieAppler, Jan 28, 2013
    Last edited by a moderator: Jan 29, 2013

    macrumors member

    Joined:
    Mar 15, 2012
    #1
    Code:
    wifiReach = [ITMReachability reachabilityForLocalWiFi];
    	[wifiReach startNotifier];
    	
    	NetworkStatus netStatus = [wifiReach currentReachabilityStatus];
        BOOL connectionRequired= [wifiReach connectionRequired];
    
    switch (netStatus)
        {
            case NotReachable:
            {
                statusString = @"Access Not Available";
                connectionRequired= NO;
                break;
            }
                
            case ReachableViaWWAN:
            {
    			NSLog(@"WWAN is reachable");
    			wifiAvailable = YES;
                statusString = @"Reachable WWAN";
    			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Yes Reachable Login"
    															message:@"Please enter the correct login details."
    														   delegate:nil
    												  cancelButtonTitle:@"OK"
    												  otherButtonTitles:nil, nil];
    			[alert show]
    			;            break;
            }
            case ReachableViaWiFi:
            {
    		
    			wifiAvailable = YES;
    			statusString= @"Reachable WiFi";
                break;
    		}
        }
    
    I have a login screen. On entering username and password app should check for WIFI/Cell and launch a web service. But on the device, when i turn off WiFi on purpose and try to use cell, it wont go ahead. I am stuck at login screen. How should i let my app work on cell(4g) as well.?If you need more info, please ask.Thanks
     
  2. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    Your code only checks for wwan which is wifi you need to check for a host traceability instead on the other interface.
     
  3. thread starter macrumors member

    Joined:
    Mar 15, 2012
    #3
    @KoolStar. How do i do that? Can you give me an example.
     
  4. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
  5. macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #5
    Why are you specifically checking reachability for wifi. Why not use reachabilityForInternetConnection or reachabilityWithHostName if you need to check a particular host address

    edit: for example, instead of

    Code:
    wifiReach = [ITMReachability reachabilityForLocalWiFi];
    try

    Code:
    wifiReach = [ITMReachability reachabilityForInternetConnection];
    Now, obviously you would maybe want to change the name of that to something other than wifiReach, but you get the idea
     
  6. thread starter macrumors member

    Joined:
    Mar 15, 2012
    #6
    @waterskier2007. Thanks. That solved my problem.
     

Share This Page