ios - Fetching reminders in background using EventKit -


i creating apple watch app has button makes call parent ios app.

wkinterfacecontroller.openparentapplication(message, reply: {             (response: [nsobject:anyobject]!, error: nserror!) in     // processing data ios app }) 

the ios app responds retrieving reminders using eventkit, so:

eventstore.fetchremindersmatchingpredicate(predicate, completion: {                 [unowned self] reminders in     // sending data reply apply watch }) 

when parent app in foreground, works charm. when make app go background, strange happens. call ekeventstore, eventstore.fetchremindersmatchingpredicate(predicate), never calls completion block. never send reply apple watch because of that?

so going wrong? suspect bug in eventkit, or maybe calling eventkit in background not supported. can shed light on this?

i figured out! before letting ekeventstore spawn async process, have start background task. when complete async call, have explicitly end background task.

// first let ios know you're starting background task let taskidentifier = application.beginbackgroundtaskwithexpirationhandler() {     () -> void in     // when task taking long } // async call ekeventstore eventstore.fetchremindersmatchingpredicate(predicate, completion: {             [unowned self] reminders in     // have do, , afterwards end background task:     application.endbackgroundtask(taskidentifier) }) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -