ios - App enters background determine current ViewController -
i working on ios app , want add notification notification center if , if user looking @ view controller when left app. app has count down timer , if looking @ count down timer , go send text or other app send notification once timer @ 0. if on view controller have no need send notification. great thanks.
within uiviewcontroller
wish detect app going background going need register uiapplicationwillresignactivenotification
, uiapplicationwillterminatenotification
notifications nsnotificationcenter
when viewwillappear
called.
nsnotificationcenter .defaultcenter() .addobserver(self, selector: selector("callback"), name: uiapplicationwillresignactivenotification, object: nil) nsnotificationcenter .defaultcenter() .addobserver(self, selector: selector("callback"), name: uiapplicationwillterminatenotification, object: nil)
when screen calls method handling notification, schedule uilocalnotification
trigger @ current time, plus timer count. can use init(timeintervalsincenow:)
on nsdate
this.
var firedate = nsdate(timeintervalsincenow: 25) var localnotification = uilocalnotification() localnotification.firedate = firedate uiapplication .sharedapplication() .schedulelocalnotification(localnotification)
and remove uiviewcontroller
observer.
nsnotificationcenter .defaultcenter() .removeobserver(self)
Comments
Post a Comment