Programmatically getting the iPhone's carrier

2020-06-16 09:59发布

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.

2条回答
狗以群分
2楼-- · 2020-06-16 10:15

You made me curious and I found out that it's actually *3001#12345#* (hashes and stars exchanged).

查看更多
聊天终结者
3楼-- · 2020-06-16 10:21

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);
查看更多
登录 后发表回答