iPhone - how to determine carrier of the device (AT&T, Verizon, etc?)

两盒软妹~` 提交于 2019-12-03 05:48:41

问题


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


回答1:


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];



回答2:


Heres the Swift version:

import CoreTelephony

let phoneInfo = CTTelephonyNetworkInfo()
let phoneCarrier = phoneInfo.subscriberCellularProvider
print(phoneCarrier?.carrierName)



回答3:


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.



来源:https://stackoverflow.com/questions/8161235/iphone-how-to-determine-carrier-of-the-device-att-verizon-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!