Reachability not working as expected

前端 未结 6 904
不思量自难忘°
不思量自难忘° 2021-02-19 02:53

Downloaded Reachability from Apple, using this method to check for an active connection:

-(BOOL)isReachable{

    Reachability *r = [Reachability reachabilityWit         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-19 03:26

    Another complete answer:

    -(BOOL) isReachable:(NSString *)url
    {
        //Retrieve the host name by given url address.
        NSString *hostName = [[NSURL URLWithString:url] host];
        Reachability *r = [Reachability reachabilityWithHostName:hostName];
    
        if(NotReachable == [r currentReachabilityStatus]) {
            NSLog(@"Not Reachable");
            return NO;
        }
        NSLog(@"Reachable");
        return YES;
    }
    

提交回复
热议问题