SWIFT: How can I use the CellularProviderDidUpdateNotifier Subscriber with Swift

I want to use the CellularProviderDidUpdateNotifier subscriber in Swift, but I don’t know how and where it can be placed.
Any ideas? I searched for this, but only Objective-C samples are available.

+5
source share
2 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        
}

the carrier will be of type CTCarrier.

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

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

and it looks a lot cleaner.

+2
source

, : SIM- ios? :

override init() {
    super.init()
    print("init");

    let info = CTTelephonyNetworkInfo()
    info.subscriberCellularProviderDidUpdateNotifier = self.cellularProviderDidUpdate
}
func cellularProviderDidUpdate(inCTCarrier: CTCarrier) {
    print("event")
}

import CoreTelephony

-1

Source: https://habr.com/ru/post/1628836/


All Articles