10

検索しましたが、私のような問題は見つかりませんでした。私はそれが私が見てきたものだと確信しています。

トニーミリオンの到達可能性ブロック方式を使用しています。インターネットがある場合とない場合にうまく機能しています。アラートが表示され、正常に機能します。

しかし、インターネットがないときにインターネットに接続すると、同じアラートがポップアップ表示されます

私のコードは

-(void)reachabilityBlock
{
// 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 = YES;


reach.reachableBlock = ^(Reachability * reachability)
{
    dispatch_async(dispatch_get_main_queue(), ^{
        //NSLog(@"REACHABLE! block");
        [self newsTableViewRefresher];
    });
};

reach.unreachableBlock = ^(Reachability * reachability)
{

        dispatch_async(dispatch_get_main_queue(), ^{
            //NSLog(@"UNREACHABLE! block");

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"No Network found!"
                                                            message: @"You have no wifi or cellular connection available. Please connect to a WIFI or cellular network."
                                                           delegate: self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];

            [alert show];


        });

};


[reach startNotifier];
[self.refreshControl endRefreshing];

 }

私の質問は、インターネットに接続すると、到達不能アラートがポップアップするのはなぜですか?

お時間をいただきありがとうございます

4

1 に答える 1

2

これは私が最後に行ったことであり、私のために仕事を成し遂げました。ブロックを使用してみましたが、問題を解決するのが面倒だったようです。お役に立てれば。

Reachability *reach = [Reachability reachabilityWithHostname:@"www.jportdev.com"];
if ([reach isReachable]){
    // Reachable
    //NSLog(@"is reachable.......");
}else{
    // not Reachable
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Network is unavaliable!" message:@"Some content in this application might not be avaliable without network connectivity." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    alert = nil;
}
于 2013-11-01T01:58:21.810 に答える