0

I use Reachability demo to check wifi connect, it work fine, now, i want use it in a network extension

Set callback is ok, but it nerver callback even network connect is change.

SCNetworkReachabilityContext context = {0, (__bridge void *)(self), NULL, NULL, NULL};
if (SCNetworkReachabilitySetCallback(_reachabilityRef, ReachabilityCallback, &context)) // return YES {
    if (SCNetworkReachabilityScheduleWithRunLoop(_reachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)) { //return YES
    //...
    }
}

never call this:

static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* info){
    //...
}
waitianlou
  • 563
  • 3
  • 15
  • Possible duplicate of [How to use SCNetworkReachability in Swift](https://stackoverflow.com/questions/25623272/how-to-use-scnetworkreachability-in-swift) – Krunal Jun 14 '17 at 09:47
  • Thanks, i read this question, but want my problem is use this code in network extension – waitianlou Jun 14 '17 at 09:56
  • Solve the problem by set callback in main thread – waitianlou Jul 04 '17 at 02:04
  • You can answer, your own question. Please share solution here by posting an answer, so It would be helpful to others. – Krunal Jul 04 '17 at 04:43

1 Answers1

0

Solve the problem by set callback in main thread,because if the thread is dead,it will never call back.

waitianlou
  • 563
  • 3
  • 15