FatihA FatihA - 1 year ago 194
Swift Question

SWIFT: How I can use subscriberCellularProviderDidUpdateNotifier with Swift

I want use subscriberCellularProviderDidUpdateNotifier in Swift, but I don't know how and where it can be placed.
Any ideas? I have searched for that, but only Objective-C samples are available.

Answer Source

In Objective C you just need to use "set" and the name of the property block while in Swift you need to assign it:

// Declare your class member
let networkInfo = CTTelephonyNetworkInfo();

// In viewDidLoad or in your custom method
networkInfo.subscriberCellularProviderDidUpdateNotifier = { carrier in
    // Do whatever you wanna do when a callback comes        

carrier will be of type CTCarreir.

Of course, you can always use the $0 which refers to CTCarreir argument:

networkInfo.subscriberCellularProviderDidUpdateNotifier = { 
 // Do whatever you need to do with it

and it looks a lot more cleaner.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download