From d1361ac4d37be184ad82b70199e06a96c955a563 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Fri, 31 Oct 2014 14:34:27 +0100 Subject: [PATCH] Fix: trigger networkChanged notification also when wifi SSID changed (not only when connectivity changed) --- Classes/LinphoneManager.m | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index faeeca9e7..3673649cd 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -955,6 +955,10 @@ static void linphone_iphone_is_composing_received(LinphoneCore *lc, LinphoneChat #pragma mark - Network Functions +- (SCNetworkReachabilityRef) getProxyReachability { + return proxyReachability; +} + + (void)kickOffNetworkConnection { /*start a new thread to avoid blocking the main ui in case of peer host failure*/ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @@ -989,6 +993,14 @@ static void showNetworkFlags(SCNetworkReachabilityFlags flags){ [LinphoneLogger logc:LinphoneLoggerLog format:"kSCNetworkReachabilityFlagsIsWWAN"]; } +static void networkReachabilityNotification(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { + LinphoneManager *mgr = [LinphoneManager instance]; + SCNetworkReachabilityFlags flags; + if (SCNetworkReachabilityGetFlags([mgr getProxyReachability], &flags)) { + networkReachabilityCallBack([mgr getProxyReachability],flags,nil); + } +} + void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* nilCtx){ showNetworkFlags(flags); LinphoneManager* lLinphoneMgr = [LinphoneManager instance]; @@ -1069,6 +1081,15 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach proxyReachability = nil; } + // This notification is used to detect SSID change (switch of Wifi network). The ReachabilityCallback is + // not triggered when switching between 2 private Wifi... + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), + NULL, + networkReachabilityNotification, + CFSTR("com.apple.system.config.network_change"), + NULL, + CFNotificationSuspensionBehaviorDeliverImmediately); + proxyReachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)&zeroAddress); if (!SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack, ctx)){ @@ -1079,6 +1100,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach [LinphoneLogger logc:LinphoneLoggerError format:"Cannot register schedule reachability cb: %s", SCErrorString(SCError())]; return; } + // this check is to know network connectivity right now without waiting for a change. Don'nt remove it unless you have good reason. Jehan SCNetworkReachabilityFlags flags; if (SCNetworkReachabilityGetFlags(proxyReachability, &flags)) {