问题
Is there a way to get the iPhone's carrier, and/or the current signal strength, using Objective-C? I know how to determine if a data connection is present, and whether or not that connection is wi-fi vs. cellular. I also know that you can manually place the iPhone into "field test" mode by going to the phone app, and dialing #3001*12345*# and hitting Send.
回答1:
You made me curious and I found out that it's actually *3001#12345#* (hashes and stars exchanged).
回答2:
This probably won't pass Apple's review, but you can use CTTelephony notifications. First, link against CTTelephony. Now just use this:
static void callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
CFShow(name)
NSString *sName = name;
if ([sName isEqualToString:@"kCTIndicatorsSignalStrengthNotification"]) {
if (userInfo) CFShow(userInfo);
}
}
And this to subscribe:
id ct = CTTelephonyCenterGetDefault();
CTTelephonyCenterAddObserver(
ct,
NULL,
callback,
NULL,
NULL,
NULL);
来源:https://stackoverflow.com/questions/1270098/programmatically-getting-the-iphones-carrier-signal-strength