Hari Hari - 1 year ago 98
Swift Question

Where should i put the function?

I created a function which checks whether the iPhone is charging or not using

. Where should I call the function so that it monitors the status throughout the app session? The Function is called "connectivityStatus", at present it's in

Language : Swift 3

Platform : iOS 10 (Using UIDevice)

Answer Source

Or you can use a Timer():

// in viewDidAppear()
var timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(YourClassName.function) , userInfo: nil, repeats: true)

//outside viewDidAppear()
func function(){

This check the status every 0.5 seconds! Hope this Helps!

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