Accurately reading of iPhone signal strength

iphone, objective-c, signals, xcode

Solution

Ok I think I have the correct solution now, which was a bit simpler in the end.

The issue with the CTGetSignalStrength() method is that it works normally, but if you remove a sim, it reports the last signal before the removal. I found another method in the same framework called CTSIMSupportGetSIMStatus(), also undocumented, which can tell you if a SIM is currently connected. Using both as follows should confirm the current network signal.

First declare the methods:

NSString * CTSIMSupportGetSIMStatus();
int CTGetSignalStrength();

Then check connectivity to cell network like so:

NSString *status = CTSIMSupportGetSIMStatus();
int signalstrength = CTGetSignalStrength();
BOOL connected = ( [status isEqualToString: @"kCTSIMSupportSIMStatusReady"] && signalstrength > 0 );

Problem

There are a few questions on this already, but nothing in them seems to provide accurate results. I need to determine simply if the phone is connected to a cell network at a given moment. http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Reference/CTCarrier/Reference/Reference.html This class seems to be documented incorrectly, returning values for mobileCountryCode, isoCountryCode and mobileNetworkCode where no SIM is installed to the phone. carrierName indicates a 'home' network or a previous home network if the phone has been unlocked. I also looked up and found some people claiming the following to work, which uses an undocumented method of the CoreTelephony framework, but the results have been useless to me, reporting seemingly random figures, where perhaps it is not itself updating consistently. ``` -(int) getSignalStrength { void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY); int (*CTGetSignalStrength)(); CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength"); if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength"); int result CTGetSignalStrength(); dlclose(libHandle); return result; } ``` Thanks. Edit: The app is connected to an internal wifi and must remain so, making a reachability check more difficult.

Original source