Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should i put the function?

I created a function which checks whether the iPhone is charging or not using UIDevice. 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 viewWillAppear.

Language : Swift 3
Platform : iOS 10 (Using UIDevice)

like image 383
Hari Avatar asked Aug 26 '16 13:08

Hari


1 Answers

Hari please define a function in Appdelegate.h and give the defination of the function in Appdelegate.m . Now you can use this function through the app like this [[Appdelegate appdelegate] "Name of your function"]. I hope this will help. Paste the below code in Appdelegate.m inorder to use appdelegate .

+(AppDelegate*)appDelegate
{
    return (AppDelegate*)[UIApplication sharedApplication].delegate;
}

swift

class func appDelegate() -> AppDelegate {
return (UIApplication.sharedApplication().delegate as! AppDelegate)
 }
like image 80
Prakash Avatar answered Oct 07 '22 17:10

Prakash