Search code examples
iosobjective-ccore-locationuilocalnotificationgeofencing

UILocalNotification Geofence: Ignore exiting region


I want to use the new Geofence API of iOS 8 (scheduleLocalNotification:).

I schedule a UILocalNotification with a region and so on. Everything works, but how can I differentiate between ENTERING and EXITING a region, resp. ignore EXITING?

iOS always displays/sends a notification, but I only want a notification when the user enters the region.

Right now I think I have to stick to the "old" startMonitoringForRegion: API.

Is that correct?


Solution

  • You can set region.notifyOnExit = NO to only receive notifications when you enter a region. You can also set region.notifyOnEntry = NO to only receive notifications when you exit a region.

    If you want to monitor both, while still being able to tell if it is an entry or an exit, I see two options. The first option would be to schedule two notifications, one where notifyOnExit is false and one where notifyOnEntry is false. The second option is to use the existing startMonitoringForRegion api to monitor both. It depends on the use case.

    Keep in mind that there is a limit to the number of regions that can be monitored (currently 20 per application I believe). I'm not sure if monitoring the same region twice counts as one or two in this case.

    Hope this helps.