iOSSinger / SGNetObserver

iOS完美的网络状态判断工具
MIT License
252 stars 51 forks source link

都是 start 吗 #2

Open wangbiye opened 7 years ago

wangbiye commented 7 years ago

你这两个方法写的一样啊, 都是 start

- (void)startNotifier{
    [self.hostReachability startNotifier];
    [self.pinger startNotifier];
}

- (void)stopNotifier{
    [self.hostReachability startNotifier];
    [self.pinger startNotifier];
}

还有就是我想检测当前手机能不能连接到 google, 然后给我返回只是 wifi 网络, 并没有告诉我是不是通


- (SGNetObserver *)netObserver {
    if (!_netObserver) {
        _netObserver = [SGNetObserver observerWithHost:@"www.google.com"];

    }
    return _netObserver;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if ([[BONLocationManager manager] isChina]) {
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(networkStatusChanged:)
                                                     name:SGReachabilityChangedNotification
                                                   object:nil];

        [self.netObserver startNotifier];
    }
}

- (void)networkStatusChanged:(NSNotification *)notify{
    NSLog(@"notify-------%@",notify.userInfo);
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:SGReachabilityChangedNotification
                                                  object:nil];
    [self.netObserver stopNotifier];
}
songhongkang commented 7 years ago

还有就是我想检测当前手机能不能连接到 google, 然后给我返回只是 wifi 网络, 并没有告诉我是不是通... 怎么知道网络通不通,解决了吗

iOSSinger commented 7 years ago

@songhongkang 如果想知道网络通不通,需要发个请求到google服务器,ping不能判断vpn,代理之类的

songhongkang commented 7 years ago

博主 我QQ:139994824 请教几个问题