2

私のiPhoneアプリでは、ユーザーはインターネットからWi-Fi経由でデータをダウンロードするか、3G/キャリアデータをダウンロードするかを設定できます。

どうすればそれをプログラムで行うことができますか?

言い換えれば、どうすればiPhoneにwifiからではなくキャリアデータからデータを取得させることができますか?

何か提案はありますか?

4

4 に答える 4

3

iPhoneがWiFiに接続されている場合、プログラムでセルラーネットワークを使用してダウンロードするように強制することはできません。

于 2012-01-05T10:50:32.020 に答える
2

電話がWiFiに接続されている場合、iPhoneにWiFiの代わりにキャリアデータ(3G /エッジ)を使用させることはできません。SCNetworkReachabilityGetFlags関数を使用して、 WiFiを使用しているか、キャリアデータ接続を使用しているかを判断できます。

ユーザーがWiFiに接続している場合は、アプリが携帯通信会社のデータでのみ機能することを示すメッセージをポップアップ表示し、ユーザーにWiFiをオフにしてアプリを再起動するように依頼します。ボーダフォンポルトガルがより多くの(高価な)キャリアデータを使用するように強制する愚かな試みで多くのアプリに対してそれを行うのを止めなかったとしても、それはあなたのユーザーの地獄を苛立たせるだけなので、私はこれをお勧めしません。

于 2012-01-05T11:11:27.603 に答える
1

これがあなたに役立つかどうかはわかりません:

http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

于 2012-01-05T10:53:47.470 に答える
1

そのためには、電話の状態を検出する必要があり、電話がWi-Fiを使用しているときに気象データが転送されていないことを簡単に識別できます。

-(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;
            }
        }
    }

詳細については、このリンクをご覧ください。

于 2012-01-05T11:57:01.790 に答える