Question

In my iphone app, the user can set whether he wants to download data from internet via wifi or 3G/Carrier data.

How can we do that programatically?

In other words, how can I force iphone to get data from carrier data not from wifi?

Any suggestion guys?

Was it helpful?

Solution

You can't force the iPhone to use carrier data (3G / Edge) instead of WiFi if the phone is connected to WiFi. You can use the SCNetworkReachabilityGetFlags function to determine if you're on WiFi or have a carrier data connection.

What you could do is, if the user is connected to WiFi, pop up a message saying that your app only works with carrier data and ask the user to switch off WiFi and restart the app. I would not recommend this though as it will just irritate the hell out of your users, although this didn't stop Vodafone Portugal from doing it for a number of their apps in a silly attempt to force you to use more (expensive) carrier data.

OTHER TIPS

You can't, if the iPhone is connect to WiFi you can not programmaticly force it to use the cellular network to download.

For that you need to detect the state of the phone and you can easily identifies the weather data isn't transfer when a phone uses the wifi.

-(void) viewWillAppear:(BOOL)animated
{
    // check for internet connection

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:)  name:kReachabilityChangedNotification object:nil];

    internetReachable = [[Reachability reachabilityForInternetConnection] retain];        

    [internetReachable startNotifier];        

    // check if a pathway to a random host exists        

    hostReachable = [[Reachability reachabilityWithHostName: @"www.apple.com"]  retain];

     [hostReachable startNotifier];        

    // now patiently wait for the notification

}



- (void) checkNetworkStatus:(NSNotification *)notice     {      

    // called after network status changes     

    NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
    switch (internetStatus){
        case NotReachable:
            {
                NSLog(@"The internet is down.");
                self.internetActive = NO;
                 break;
            }
            case ReachableViaWiFi:
            {
                NSLog(@"The internet is working via WIFI.");
                self.internetActive = YES;
                break;
            }
            case ReachableViaWWAN:
            {
                NSLog(@"The internet is working via WWAN.");
                self.internetActive = YES;
                break;
            }
        }
        NetworkStatus hostStatus = [hostReachable currentReachabilityStatus];
        switch (hostStatus)
        {
            case NotReachable:
            {
                NSLog(@"A gateway to the host server is down.");
                self.hostActive = NO;
                break;
            }
            case ReachableViaWiFi:
            {
                NSLog(@"A gateway to the host server is working via WIFI.");
                self.hostActive = YES;
                break;
            }
            case ReachableViaWWAN:
            {
                NSLog(@"A gateway to the host server is working via WWAN.");
                self.hostActive = YES;
                break;
            }
        }
    }

more information visits this link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top