简体   繁体   中英

iBeacons and local notifications

I have developed a small iBeacon based application, when the application detects one of our iBeacons makes a call to a web service to obtain a data set and send a local notification to the user. All this is working correctly.

I have now raised the idea that these local notifications could vary over short time intervals, with new content. The problem is that if the user does not leave the region of the iBeacon and reenters, the application will not "wake up" and the user will not receive the new updated notification.

I do not know if this could be solved somehow or actually the approach to make something like that should not be related to technology of iBeacons.

I'm really lost and do not know if anyone would know advise me on how to raise it.

You can schedule local notifications to be delivered at a specific time: use the fireDate and timeZone properties of the UILocalNotification , and then use scheduleLocalNotification instead of the presentLocalNotificationNow method of the UIApplication.

With that in mind you could do this: upon an "enter" event, retrieve a few notifications to be showed to the user over a certain time period while they remain in the zone, schedule them appropriately and let iOS do the delivering.

If the user exits the zone before all the notifications are shown, you can cancel the remaining local notifications using cancelLocalNotification or cancelAllLocalNotifications methods.

In order to do this, you need to get the app to run in the background while beacons are in the vicinity. This would allow you to periodically check for updated content associated with the beacon and then display notifications under two conditions:

  1. When a beacon first appears, and there is a message associated with that beacon.
  2. The message associated with the beacon above changes during the time the beacon is still visible.

As you mention, the second item is a problem, because you need a way to continually check to see if there is updated content despite the fact that iOS will suspend your app within 5 seconds of beacon detection in the background.

A few options, each of which have downsides:

  1. You can use a custom hardware beacon that changes its identifier every minutes or so (eg the minor goes back and forth between 0 and 1). This would allow you to monitor two regions and re-trigger on each every minute the beacon is in the vicinity. Downside: This requires building a custom beacon.

  2. You can make your app request an extra 3 minutes of background running time during which you can check for changed messages. Downside: You only get three minutes to display changed messages.

  3. You can specify extra background modes in your .plist so you can continue running in the background. Downside: Apple won't approve your app for distribution in the store unless you have a good reason to run in the background (eg a navigation app or a music player app.)

  4. You can send a push notification to your app each time the message changes, which would wake up your app in the background so you could display an updated notification if a beacon is in the vicinity. Downside: Setting up push notifications are a bit complex, delivery can be slow, and is not guaranteed.

Read here for more info on some of these options: http://developer.radiusnetworks.com/2014/11/13/extending-background-ranging-on-ios.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM