>我使用可达性演示来检查wifi连接,它工作正常,现在,我想在网络扩展中使用它
设置回调是可以的,但它使回调紧张,即使网络连接是更改的。
SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) // return YES {
if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) { //return YES
//...
}
}
永远不要这样称呼:
static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info){
//...
}
通过在主线程中设置回调来解决问题,因为如果线程死了,它永远不会回调。