Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen to Calendar events when application in background iOS?

I wrote application for Android that listens on incoming Calendar events and triggers my flow when application in background.

Now I try to do the same for iOS.

I read a lot of stuff and ran some demos that use EKEventStore and background fetch.

However this approach does not satisfy me.

Is there other way to do that?

[EDIT]

Application uses public API only.

Thanks,

like image 250
snaggs Avatar asked Mar 26 '14 22:03

snaggs


2 Answers

The short answer is you can't. Apple will not allow any app to do things like this in the background, as it requires turning the CPU on when it would otherwise be turned off.

When your app is running, you can read all events in the near future (say, two weeks out?) and setup a "local" push notification for the event time.

Also, if the user launches your app fairly often then Apple will allow your app to refresh using Background App Refresh. The device will typically do this in the morning before whatever time the user usually wakes up and turns their phone on for the first time each day, and throughout the day also, based on the user's activity. You can do anything you want during the background app refresh.

Another spanner in the works is how Apple's full disk encryption works. If the phone is locked, there really isn't much your app can do. Most data on the phone is encrypted with the user's passcode. Until the user enters their passcode not much can be done. In this case background app refresh will run as soon as they enter their passcode, but before they launch your app.

Maybe you could have a remote server send push notifications to the phone as well. Not sure if this is an option for you at all or not. Obviously this means the server would need access to the user's calendar data.

like image 115
Abhi Beckert Avatar answered Oct 06 '22 08:10

Abhi Beckert


In general, the Android model of background execution doesn't apply to iOS.

You can register for calendar events as shown below, but your application will only be notified when it is running. On iOS, that means it is either in the foreground, recently backgrounded and still running, or has been launched/woken up by the system as part of a designated background mode (e.g. background fetch, location updates, VoIP, etc.).

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(receiveEventStoreChangedNotification:)
                                             name:EKEventStoreChangedNotification
                                           object:eventStore];

If your application has a need for one of the designated background modes, you will at least get notifications from time to time (when you are woken up). I've seen approved apps use location updates just to get more execution time, of course YMMV.

like image 34
mygzi Avatar answered Oct 06 '22 06:10

mygzi