ios - Executing code, when the application is in background not working on physical device (SWIFT) -


i making app, reliant on executing minor code in background , ran peculiar problem.
app has timer, nstimer(). principle behind of similiar of timer (in clock application, installed on ios devices), meaning, when timer ends uilocalnotification displayed.

everything works expected when run on emulated device in xcode, when test on iphone, there no notifications. along lines of:

var end = timerhasended() if end == true{     println("the timer has ended") } 

and not working. checked if application detects background uiapplicationstate doing , not on physical device. interestingly enough, on emulated device.

i tried running timer on background thread, using qos_class_background , dispatch_async no avail. can me?

could schedule uilocalnotification appear after delay, when delay remaining time left in alarm?

var date: nsdate = /*time until timer expires*/ let app = uiapplication.sharedapplication() let oldnotifications = app.scheduledlocalnotifications if oldnotifications.count > 0 {     app.cancelalllocalnotifications() }  let alarm = uilocalnotification() alarm.firedate = date alarm.timezone = nstimezone.defaulttimezone() alarm.repeatinterval = 0 alarm.soundname = "myalarmsound.caf" alarm.alertbody = "do something!"  app.schedulelocalnotification(alarm) 

i wrote code obj-c example provided apple.

https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/backgroundexecution/backgroundexecution.html


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -