首页 文章

如何从运营商数据/ 3GS下载数据而不是wifi?

提问于
浏览
2

在我的iphone应用程序中,用户可以设置是否要通过wifi或3G / Carrier数据从互联网下载数据 .

我们怎么能以编程方式做到这一点?

换句话说,我如何强制iphone从运营商数据获取数据而不是从wifi?

有什么建议吗?

4 回答

  • 1

    如果手机连接到WiFi,则无法强制iPhone使用运营商数据(3G / Edge)而不是WiFi . 您可以使用SCNetworkReachabilityGetFlags功能来确定您是使用WiFi还是拥有运营商数据连接 .

    您可以做的是,如果用户连接到WiFi,则会弹出一条消息,指出您的应用仅适用于运营商数据,并要求用户关闭WiFi并重新启动应用 . 我不会推荐这个,因为它只会激怒你的用户,尽管这并没有阻止沃达丰葡萄牙为他们的一些应用程序做这个愚蠢的尝试迫使你使用更多(昂贵的)运营商数据 .

  • 3

    你不能,如果iPhone连接到WiFi,你不能以编程方式强迫它使用蜂窝网络下载 .

  • 2
  • 1

    为此,您需要检测手机的状态,并且当手机使用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.

相关问题