iOS I can't get my carrier name
Asked Answered
M

4

5

as explained here -> Retrieving Carrier Name from iPhone Programmatically

i'm trying to get my carrier's name, i'm using this code

CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
NSLog(@"Carrier Name: %@", [carrier carrierName]);
[netinfo release];

but i receive a warning on [carrier carrierName]: Instance method '-carrierName' not found

i've added and the framework coretelephony to my project but when i execute my app it crashes!

thanks to all!

Morita answered 15/11, 2011 at 15:21 Comment(0)
J
14

Did you explicitly import CTCarrier?

#import <CoreTelephony/CTCarrier.h>
Jiggermast answered 15/11, 2011 at 16:20 Comment(3)
I was importing only <CoreTelephony/CTTelephonyNetworkInfo.h>... -.-' thank you!Morita
im getting carrier as CTCarrier (0x174059200) { Carrier name: [Carrier]Transducer
Please ask a new question. This one had to do with a build failure.Jiggermast
S
1

I have same problem too,and try to log by device:

NSLog(@"carrierName = %@",carrier.carrierName);
NSLog(@"mobileCountryCode = %@",carrier.mobileCountryCode);
NSLog(@"mobileNetworkCode = %@",carrier.mobileNetworkCode);
NSLog(@"isoCountryCode = %@",carrier.isoCountryCode);
NSLog(@"allowVOIP = %d",carrier.allowsVOIP);

result:

2012-05-29 11:48:31.466 carrierTest[357:707] mobileCountryCode = 466

2012-05-29 11:48:31.469 carrierTest[357:707] mobileNetworkCode = 97

2012-05-29 11:48:31.470 carrierTest[357:707] isoCountryCode = tw

2012-05-29 11:48:31.472 carrierTest[357:707] allowVOIP = 1

the object carrierName is "....." in run stack,actually it should be "台湾大哥大"

it seem like string encoding problem cause i can't get it? I have no idea...

you can try the other carrier SIM card.

Selfassertion answered 29/5, 2012 at 4:16 Comment(0)
S
0

Try

NSLog(@"Carrier Name: %@", carrier.carrierName);

instead.

Sabrinasabsay answered 15/11, 2011 at 15:33 Comment(2)
it says "Poperty 'carrierName' cannot be found in forward class object 'CTCarrier *'Morita
which iOS are you compiling for, by the way? 3.0 or 4.0 or?Sabrinasabsay
B
0

In Swift 5 like this

0000000100000001 for first sim

0000000100000002 for secound sim if mobile has 2 sim cards

import CoreTelephony

let networkInfo = CTTelephonyNetworkInfo()

var cc: String = ""
var mnc: String = ""
var mcc: String = ""
var cn: String = ""

if let providers = networkInfo.serviceSubscriberCellularProviders, let carrier = providers["0000000100000001"]{
            cc  = carrier.isoCountryCode ?? ""
            mnc = carrier.mobileNetworkCode ?? ""
            mcc = carrier.mobileCountryCode ?? ""
            cn =  carrier.carrierName ?? ""
 }
Bolide answered 2/12, 2022 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.