ios - What function gets called when loading app from homescreen? -


i want able change background color of app depending on time of day. believe way go saying if hour component greater whatever number, set background nighttime background, otherwise it's daytime background.

to test out worried about, threw

timelabel.text = nsdateformatter.localizedstringfromdate(nsdate(), datestyle: .nostyle, timestyle: .fullstyle) 

into viewdidload. shows time app loads. keeps updating if kill app , reload completely.

however, if user goes the home screen or goes different app, comes time isn't going updated. show time app first loaded up. if user kills app, can't relied on, correct time shown.

so in example if "switch nighttime time" 5pm, if user loads @ at @ 4:30 , goes homescreen, loads app @ 5pm, nothing changed stored time still 4:30.

i tried throwing code in viewdidappear , nothing changed.

what code run when app loaded being on homescreen or coming app?

you want key off of uiapplicationdidbecomeactivenotification event. try this:

override func viewdidload()  {     super.viewdidload()      nsnotificationcenter.defaultcenter().addobserver(         self,         selector: "applicationdidbecomeactive:",         name: uiapplicationdidbecomeactivenotification,         object: nil) }  func applicationdidbecomeactive(notification: nsnotification)  {     // when app active again.     timelabel.text = nsdateformatter.localizedstringfromdate(nsdate(), datestyle: .nostyle, timestyle: .fullstyle) }