iPhone - how to determine carrier of the device (A

2019-03-10 05:59发布

Is there a way to get information about the carrier of iPhones programmatically?

3条回答
我命由我不由天
2楼-- · 2019-03-10 06:14

1st Import #import <CoreTelephony/CTTelephonyNetworkInfo.h> as well as #import <CoreTelephony/CTCarrier.h> (make sure you have the CoreTelephone.framework installed too).

CTTelephonyNetworkInfo *phoneInfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *phoneCarrier = [phoneInfo subscriberCellularProvider];
NSLog(@"Carrier = %@", [phoneCarrier carrierName]);
[phoneInfo release];
查看更多
男人必须洒脱
3楼-- · 2019-03-10 06:16

Heres the Swift version:

import CoreTelephony

let phoneInfo = CTTelephonyNetworkInfo()
let phoneCarrier = phoneInfo.subscriberCellularProvider
print(phoneCarrier?.carrierName)
查看更多
Animai°情兽
4楼-- · 2019-03-10 06:22

While developing in Swift 3.0, You just need to import CoreTelephony in you link binary with libraries in Build phases.

// Setup the Network Info and create a CTCarrier object

 let networkInfo = CTTelephonyNetworkInfo()
 let carrier = networkInfo.subscriberCellularProvider

// Get carrier name

 print(carrier?.carrierName)

That's it.

查看更多
登录 后发表回答