1. Import: Coretelephony.framework
2. Add a header file
#import <CoreTelephony/CTTelephonyNetworkInfo.h> #import <coretelephony/ Ctcarrier.h>
3. Get the network environment
-(void) networktype{Nsarray*subviews = [[[[UIApplication sharedapplication] Valueforkey:@"StatusBar"] Valueforkey:@"Foregroundview"]subviews]; NSNumber*datanetworkitemview =Nil; for(IDSubviewinchsubviews) { if([Subview iskindofclass:[nsclassfromstring (@"Uistatusbardatanetworkitemview")class]]) {Datanetworkitemview=Subview; Break; } } Switch([[Datanetworkitemview Valueforkey:@"Datanetworktype"]integervalue]) { Case 0: NSLog (@"No WiFi or cellular"); Infolabel.text=@"No service"; Break; Case 1: NSLog (@"2G"); Infolabel.text=@"2G"; Break; Case 2: NSLog (@"3G"); Infolabel.text=@"3G"; Break; Case 3: NSLog (@"4G"); Infolabel.text=@"4G"; Break; Case 4: NSLog (@"LTE"); Infolabel.text=@"LTE"; Break; Case 5: NSLog (@"Wifi"); Infolabel.text=@"Wifi"; Break; default: Break; }}
4. Get Carrier information
+(BOOL) isinchina{cttelephonynetworkinfo*telephonyinfo =[[Cttelephonynetworkinfo alloc] init]; Ctcarrier*carrier =[Telephonyinfo Subscribercellularprovider]; //nsstring *currentcountry = [Carrier carriername];NSLog (@"[Carrier Carriername]==%@,[carrier mobilecountrycode]==%@,[carrier Mobilenetworkcode]==%@,[carrier Isocountrycode]==%@,[carrier allowsvoip]==%d", [carrier Carriername],[carrier mobilecountrycode],[carrier Mobilenetworkcode],[carrier isoCountryCode],[ Carrier Allowsvoip]); if([[Carrier Mobilecountrycode] Isequaltostring:@"460"]) { returnYES; }Else{ returnNO; } }
Get carrier's:
iOS get information about your carrier