|
From: | IVAN FERNANDEZ |
Subject: | Re: [Linphone-developers] Network reachability callback problem in Linphone iPhone |
Date: | Thu, 28 Jun 2012 13:11:19 +0200 |
-(void) setupNetworkReachabilityCallback: (const char*) nodeName withContext:(SCNetworkReachabilityContext*) ctx {
//add changes observer
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
internetReachable = [[Reachability reachabilityForInternetConnection] retain];
[internetReachable startNotifier];
//launch initial check
[self reachabilityChanged: nil];
}
- (void)reachabilityChanged:(NSNotification *)notice {
// called after network status changes
LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy([LinphoneManager getLc], &proxy);
BOOL isWifiOnly = [[NSUserDefaults standardUserDefaults] boolForKey:@"wifi_only_preference"];
NetworkStatus internetStatus = [internetReachable currentReachabilityStatus];
if (internetStatus == ReachableViaWiFi) {
NSLog(@"Internet accesible via wifi...");
linphone_core_set_network_reachable([LinphoneManager getLc],true);
if (proxy) linphone_proxy_config_expires(proxy, DEFAULT_EXPIRES);
}
else if (internetStatus != NotReachable && !isWifiOnly) {
NSLog(@"Internet accesible via wwan...");
linphone_core_set_network_reachable([LinphoneManager getLc],true);
if (proxy) linphone_proxy_config_expires(proxy, DEFAULT_EXPIRES);
}
else
[[LinphoneManager instance] kickOffNetworkConnection];
}
Hi,Very interesting indeed.Let us know the outcomes of your further findings.Cheers
Le 20 juin 2012 à 13:48, IVAN FERNANDEZ a écrit :_______________________________________________Hi,I'm facing an strange problem with the callback that detects network changes in Linphone code.The problem is that the callback is being called correctly when the wifi goes off, but it is not called again when the wifi goes on.I'm running two test (iPhone 4 iOS 5.1.1, Linphone 1.1.2 with TLS enabled):1. Wifi set to ON: I run Linphone from xcode ->wait the registration in the server -> then I go to the settings and switch off wifi -> the callback is called -> ALL IS GREAT -> then I switch wifi on again... -> the callback is not called -> ;-/2. Wifi set to OFF: I run Linphone from xcode -> no connection so the registration can not be done -> then I go to the settings and switch on wifi -> the callback is not called -> ;-/Let's take a look to the callback:void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* nilCtx) {
ms_message("Network connection flag [%x]",flags);
LinphoneManager* lLinphoneMgr = [LinphoneManager instance];
SCNetworkReachabilityFlags networkDownFlags=kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic;
if ([LinphoneManager getLc] != nil) {
LinphoneProxyConfig* proxy;
linphone_core_get_default_proxy([LinphoneManager getLc], &proxy);
struct NetworkReachabilityContext* ctx = nilCtx ? ((struct NetworkReachabilityContext*)nilCtx) : 0;
if ((flags == 0) | (flags & networkDownFlags)) {
[lLinphoneMgr kickOffNetworkConnection];
//COMMENTING THE FOLLOWING LINE THE PROBLEM IS PARCIALLY SOLVED !!!!!!!!!!!!
linphone_core_set_network_reachable([LinphoneManager getLc],false);
lLinphoneMgr.connectivity = none;
} else {
Connectivity newConnectivity;
BOOL isWifiOnly = [[NSUserDefaults standardUserDefaults] boolForKey:@"wifi_only_preference"];
if (!ctx || ctx->testWWan)
newConnectivity = flags & kSCNetworkReachabilityFlagsIsWWAN ? wwan:wifi;
else
newConnectivity = wifi;
if (newConnectivity == wwan && proxy && isWifiOnly && (lLinphoneMgr.connectivity == newConnectivity || lLinphoneMgr.connectivity == none)) {
linphone_proxy_config_expires(proxy, 0);
} else if (proxy){
linphone_proxy_config_expires(proxy, DEFAULT_EXPIRES); //might be better to save the previous value
}
if (lLinphoneMgr.connectivity == none) {
linphone_core_set_network_reachable([LinphoneManager getLc],true);
} else if (lLinphoneMgr.connectivity != newConnectivity) {
// connectivity has changed
linphone_core_set_network_reachable([LinphoneManager getLc],false);
if (newConnectivity == wwan && proxy && isWifiOnly) {
linphone_proxy_config_expires(proxy, 0);
}
linphone_core_set_network_reachable([LinphoneManager getLc],true);
}
lLinphoneMgr.connectivity=newConnectivity;
ms_message("new network connectivity of type [%s]",(newConnectivity==wifi?"wifi":"wwan"));
}
if (ctx && ctx->networkStateChanged) {
(*ctx->networkStateChanged)(lLinphoneMgr.connectivity);
}
}
}
The most curious thing is that if I comment the invocation to "linphone_core_set_network_reachable" that I've pointed in the callback the first test works great and the callback is called on both on/off wifi changes (what makes me suspect that the problem can be caused by a silly issue), but the second test remains failing.
¿Anyone has that point running? ¿Any ideas about why the callback is not called any more at some point?
PD: On Android, the same test with reachability works great on all the cases.
Thanks in advanced..
Linphone-developers mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/linphone-developers
_______________________________________________
Linphone-developers mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/linphone-developers
[Prev in Thread] | Current Thread | [Next in Thread] |