ios - Background Task works on Simulator only -
background
i have created sample timer app counts specific value down zero. label displays how time left.
every time nstimer (1s interval) calls countdownsecs() prints how many seconds left , executes println("countdownsecs()"). when countdown has reached 0 seconds sends local push notification.
when running in simulator works , 5 minutes stays in background , continuously prints seconds left , countdownsecs().
on other hand, when running on actual device (iphone 4s, ios 8.1.3 , ios 8.3) stops when entering background. (it worked before on 1 w/ ios 8.3. thought might because iphone 4s can not handle iphone 4s simulator works fine.)
code
in appdelegate's applicationdidenterbackground() have following code uilocalnotification:
var alarmtime: nsdate = nsdate() var app: uiapplication = uiapplication.sharedapplication() var notifyalarm: uilocalnotification = uilocalnotification() //counterall contains total amount of seconds alarmtime.datebyaddingtimeinterval(nsdate.timeintervalsincereferencedate()) notifyalarm.firedate = nsdate(timeintervalsincenow: counterall) notifyalarm.timezone = nstimezone.defaulttimezone() notifyalarm.repeatinterval = nscalendarunit(0) notifyalarm.soundname = "time's up.m4a" notifyalarm.alertbody = "time's up! - timer has ended." app.schedulelocalnotification(notifyalarm) question
can change fix issue?
thanks in advance :)
by default, nstimer won't work in background in actual devices. works in simulators only. however, can execute background tasks uiapplications method beginbackgroundtaskwithexpirationhandler, apple has set hard limit background execution (180 seconds if remember correctly).
it advisable use uilocalnotifications instead of background tasks.
Comments
Post a Comment