1

iOSアプリでインターネット接続をテストするメソッドを実装しました。問題は、携帯電話ではなく、wifi経由でインターネット接続をテストする方法だけが欲しいということです。それ、どうやったら出来るの?:-)PS私は最新バージョンのXcodeとiOS6を使用しています。

NSURL *scriptUrl = [NSURL URLWithString:@"http://10.247.245.87/stores/test.html"];
NSData *data = [NSData dataWithContentsOfURL:scriptUrl];
if (data != nil){
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Success"
                                                   message: @"You're connected to the server"
                                                  delegate: self
                                         cancelButtonTitle: @"Close"
                                         otherButtonTitles:nil];

//Show Alert On The View
[alert show];
}

else {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Connection Failed"
                                                   message: @"Please connect to network and try again"
                                                  delegate: self
                                         cancelButtonTitle: @"Close"
                                         otherButtonTitles:nil];

//Show Alert On The View
[alert show];
}
4

4 に答える 4

2

Reachabilityクラスを調べましたか?

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

それはおそらくあなたにもっと多くの柔軟性を提供し、Appleがすでに仕事をしているのならなぜあなた自身を転がすのか:)これが役立つことを願っています!

于 2012-10-26T12:41:06.963 に答える
2

TonyMillionReachabilityクラスを確認 してください

isReachableViaWiFiWi-Fiのみを確認できる方法が必要です

// allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname:@"www.google.com"];

// tell the reachability that we DONT want to be reachable on 3G/EDGE/CDMA
reach.reachableOnWWAN = NO;
于 2012-10-26T12:44:01.200 に答える
0

この同様の質問を見たことがありますか:

iOSまたはOSXでアクティブなインターネット接続を確認するにはどうすればよいですか?

その上で最も高く投票された質問は、きちんとした回避策へのgithubリンクを提供し、インターネット接続がWi-FiまたはWWAN(セルラー)を介してアクティブであるかどうかを示します

于 2012-10-26T12:44:46.323 に答える
0

ネットワーク接続をチェックする機能を提供するAFNetworking-

AFNetworkReachabilityManager.sharedManager().setReachabilityStatusChangeBlock { (status: AFNetworkReachabilityStatus) -> Void in
        // check your connectivity...
    }
于 2014-10-08T13:15:21.977 に答える