FatihA FatihA - 5 months ago 52
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

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 = { 
 $0      
 // Do whatever you need to do with it
}

and it looks a lot more cleaner.