Unable to get carrierName from serviceSubscriberCellularProvider.

Asked 2 years ago, Updated 2 years ago, 48 views

The subscriberCellularProvider is now deprecated in iOS 12, so
I replaced serviceSubscriberCellularProviders, but
I'm having trouble getting carrierName

The Apple document says it's a dictionary type, so I think I can get it with test["carrierName"], but what's wrong?

iflet test=CTTelephonyNetworkInfo().serviceSubscriberCellularProviders{
  print(test)//I
  print(test["carrierName")/II
}

[debug window]

//print I
["~": CTCarrier(~~){
    Carrier name: [Softbank]
    Mobile Country Code: [440]
    Mobile Network Code: [20]
    ISO Country Code: [jp]
    Allows VOIP? [YES]
}
]

// print II
nil

swift

2022-09-30 21:43

1 Answers

print I output, in my environment:

["0000000100000001": CTCarrier(0x2825fbe10){
    Carrier name: [Softbank]
    Mobile Country Code: [440]
    Mobile Network Code: [20]
    ISO Country Code: [jp]
    Allows VOIP? [YES]
}
]

I can't find any information that I have to keep secret, but why do I hide it like ~? Apple documentation is also a bad area around here, and it's often faster to provide this kind of information.

Apple Documentation:

(Excerpt)

Each entry in the dictionary is a CTCarrier object,

Each entry in the dictionary is a CTCarrier object.

the actual value of a key isn't immediate,

The actual value of the key (in the dictionary) doesn't matter (translation: "But…", but now it's ignored)

This means that the value in this dictionary is not taken with a key like "carrierName", and that the value of type CTCarrier hangs from a non-critical key.

For example, try this

iflet providers=CTTelephonyNetworkInfo().serviceSubscriberCellularProviders{
            iflet provider=providers.first{
                print("key=\(provider.key)")
                let carrier —CTCarrier=provider.value
                print("Carrier name=\(carrier.carrierName???"?")")
            }
        }

If you look at the CTCarrier documentation, you'll soon find out how to get more information.


2022-09-30 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.