问题
In my iOS app, I support to work online as well as offline. For this I have used Apple's Reachability code. Now I want to show user is offline if the cellular mobile network is EDGE or GPRS or bad/slow network. I have used the below code( Found solution ).
Code:
CTTelephonyNetworkInfo *telephonyInfo = [CTTelephonyNetworkInfo new];
NSLog(@"Current Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
[NSNotificationCenter.defaultCenter addObserverForName:CTRadioAccessTechnologyDidChangeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note)
{
NSLog(@"New Radio Access Technology: %@", telephonyInfo.currentRadioAccessTechnology);
}];
I did testing on device with 3G cellular mobile network
and got CTRadioAccessTechnologyWCDMA
successful. To test EDGE
or GPRS
or any other slow/bad network
I used Network Link Conditioner from device's developer settings but still getting CTRadioAccessTechnologyWCDMA
value.
EDIT:
After doing so many researches, I have found another solution which measures signal strength. I have tested this on iOS7 device it works but not in iOS8.4 device. Also I think this is private API so may apple will reject this.
Here is my code:
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <dlfcn.h>
int CTGetSignalStrength();
@implementation ViewController
-(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;
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
NSTimer* timer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
-(void)updateLabel{
_lblSpeed.text = [NSString stringWithFormat:@"signal strength: %d\n", CTGetSignalStrength()];
NSLog(@"signal strength: %d\n", CTGetSignalStrength());
}
@end
So any idea how we can test for EDGE or GPRS or any other slow/bad network? Is there any another solution/idea to proceed?
来源:https://stackoverflow.com/questions/33075759/how-to-test-edge-or-gprs-or-any-other-slow-bad-network