Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 839
FatihA Avatar asked Nov 08 '22 20:11

FatihA


1 Answers

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 CTCarrier.

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

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

and it looks a lot more cleaner.

like image 149
OhadM Avatar answered Dec 12 '22 22:12

OhadM