Search code examples
iosgeolocationcllocationclregion

Is there a way to set CLRegion to expire if not reached within certain time?


I'm trying to use CLRegion to mark as the end destination selected by the user so that the app will prompt the user once they've reached the destination.

The issue is that if the user plots the end destination and didn't actually reach the region. The region will be there forever! (Until one fine day, they will be prompted the message out of the blue when they finally reached.)

I can't seem to find anything regarding the expiry on the internet? Can someone enlighten me, please?


Solution

  • Not sure what problem you are trying to solve. If the region is not valid after certain date/time, just check for expiration when the geofence is finally hit and do not propagate the event all the way up to user interface.

    Keep in mind that you may not use run time variables to track expirations, as your app may be restarted many times between arming the region and actually hitting it. The quick and dirty solution would be incorporating expiration timestamp right into the region ID. But most likely you will have to use some kind of persistent storage to keep all the information related to a region.