2011-07-15 12 views
2

自分のコードで到達可能性クラスを使用して無線LANの接続を確認しています。しかし時には問題が起こるwifiがオンですが、インターネットの接続性がない、または低いです。ここで私のコードは、呼び出されたwebserviceやハングアップからの応答を待つループで動作します。私はここWebサービス からいくつかのデータを引き出しAlertViewで[OK]を打ったときコードの下 が実行され、私のコードは次のとおりです。無線LANが有効であることを確認するにはインターネットに接続していない

 Reachability *ReachObj = [Reachability reachabilityForInternetConnection]; 
    [ReachObj startNotifier]; 
    NetworkStatus remoteHostStatus = [ReachObj currentReachabilityStatus]; 

    if (remoteHostStatus==ReachableViaWiFi) 
    { 
     SecondView *ObjSecView=[[SecondView alloc]init]; 
     [self presentModalViewController:ObjSecView animated:YES]; 
    } 

    else 
     if (remoteHostStatus==NotReachable) 
    { 
     FirstView *objFrstView=[[FeedBackPopOverViewController alloc]init]; 
     [self presentModalViewController:objFrstView animated:YES];  
    } 

Guysは、私は、事前のおかげで、Plzは私を助ける目的C. に新しいメートル。私の文法上の間違いには申し訳ありません。

答えて

0

はこれを試してください。.. loginButtonTouched方法は、我々は "www.google.com" 到達可能かどうかであることを確認し

SCNetworkReachabilityFlags flags; 

SCNetworkReachabilityRef reachability=SCNetworkReachabilityCreateWithName(NULL, [@"your  web sevice url" UTF8String]); 

SCNetworkReachabilityGetFlags(reachability, &flags); 
BOOL reachable=!(flags & kSCNetworkReachabilityFlagsConnectionRequired); 

CFRelease(reachability); 
NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 


if([NSURLConnection canHandleRequest:request] && reachable) 
{ 
conn=[NSURLConnection connectionWithRequest:request delegate:self]; 

if(conn) 
{ 
    ////   

} 
else 
{ 
    [_delegate performSelector:@selector(httpDataDidFailLoadingWithReason:) 
        withObject:@"No Internet Connection" afterDelay:0.1]; 
} 

} 


-(void) httpDataDidFailLoadingWithReason:(NSString*)reason 
{ 

UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"abc" 
                message:reason 
                delegate:self cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
[alertView show]; 
[alertView release]; 

    } 
0
-(void)loginButtonTouched 
{ 
    bool success = false; 
    const char *host_name = [@"www.google.com" 
       cStringUsingEncoding:NSASCIIStringEncoding]; 

    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName 
                (NULL, host_name); 
    SCNetworkReachabilityFlags flags; 
    success = SCNetworkReachabilityGetFlags(reachability, &flags); 
    bool isAvailable = success && (flags & kSCNetworkFlagsReachable) && 
         !(flags & kSCNetworkFlagsConnectionRequired); 

    if (isAvailable) 
    { 
     NSLog(@"Host is reachable: %d", flags); 
     // Perform Action if Wifi is reachable and Internet Connectivity is present 
    } 
    else 
    { 
     NSLog(@"Host is unreachable"); 
     // Perform Action if Wifi is reachable and Internet Connectivity is not present 
    }  
} 

と呼ばれていた場合。 SCNetworkReachabilityFlagsは、インターネット接続のステータスを理解するのに役立つフラグを返します。 isAvailable変数が "true"を返す場合、Host is ReachableはWifiが到達可能であり、インターネット接続が存在することを意味します。

私たちの質問に素早く回答いただきありがとうございます。 申し訳ありませんが私の文法上の間違いがあります。

関連する問題