Beacon notification when app is not open?


#1

Hi Team…

We are using Estimote Beacons and the beacons local notification works fine when app is in foreground or backgroud. But am not able to get the notifications when app is closed or not open in background…

  1. I am trying with CLLocationManager class for ranging beacons and respective delegates like -(void)locationManager:(CLLocationManager *)manager didRangeBeacons:
    (NSArray *)beacons inRegion:(CLBeaconRegion *)region and working all the notifications in that delegate method.

  2. I had enabled requestAlwaysAuthorization for location manager…

  3. I even tried with ESTBeaconManager and respectively with the samples available in the developer forum… but i am not getting the Notifications when app is closed or not open in background…

** I am manually removing the app from background (From multitasking panel - by double clicking the home button and removing the app)…

So, can you please guide me in how to get the local notifications when the app is not open.

Thanks
Kalyan


#2

I suggest you go through our iBeacon tutorial to learn all the necessary steps for the notifications to work in the background.

You can also download the Notification app template from Estimote Cloud:
https://cloud.estimote.com/#/apps/add/notification


#3

Hey Piotr…

Thanks for the information… i had followed the tutorial and implemented the same…

  1. In my application didFinishLaunchingWithOptions i had initialized as follows…

    _beaconManager = [ESTBeaconManager new];
    _beaconManager.delegate = self;
    [_beaconManager requestAlwaysAuthorization];
    _beaconManager.avoidUnknownStateBeacons = TRUE;
    
    [_beaconManager startMonitoringForRegion:[[CLBeaconRegion alloc]initWithProximityUUID:[[NSUUID alloc]initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"] identifier:@"monitored region"]];
    
  2. and as soon as i enter beacon region, didenterregion delegate method is called…but in this delegate method i need to get the beacon details like uuid, major value and minor value… i need to use around 20-30 beacons and i am thinking to have same UUID for all the beacons and different major and minor values… So, in this delegate how can i get the details of the beacon as i need to get the information from the server based on these values…

  3. I am trying to use rangingbeacons but as i read that this won’t show notifications when the app is not open. So as i read only monitoring beacons will show the notification when the app is not open… but if i start ranging beacons after monitoring beacons like as follows, then didenterregion is never called.

    [_beaconManager startMonitoringForRegion:[[CLBeaconRegion alloc]initWithProximityUUID:[[NSUUID alloc]initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"] identifier:@"monitored region"]];
    [_beaconManager startRangingBeaconsInRegion:[[CLBeaconRegion alloc]initWithProximityUUID:[[NSUUID alloc]initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"] identifier:@"monitored region"]];
    
  4. And may i know how often this monitoring beacons will be detecting beacons as for me once it detected a beacon and i had fliped the beacon to sleep and if i keep that beacon in position after a minute or two, then i get notification with few seconds delay…

  5. So, may i know what would be idle to use like is it monitoring beacons or ranging beacons.

  6. Can you please provide the code snippet to get the beacon details in didenterregion delegate method…

Thanks
Kalyan


#4

Hi @KalyanKumar_Parise ,

I have the same problem as you , my app work fine in foreground or background but when I kill the app , nothing work for me not even monitoring.

I’m using iPhone 5c with iOS 8.4


#5

Can you try to generate an app using the Notification template on cloud.estimote.com (“Apps” section), and see if that works?


#6

@heypiotr
I did :smile: this sample use beaconNotificationsManagerager but what i’m trying to do here is when > didEnterRegion get called generate localNotification , da same when didExitRegion so each beacon will have different text message and dynamic because msg saved on server in my case and fetch it each time my app open.

But didEnterRegion / didExitRegion never called when the app closed ??

i think the documentation messing something ? can u plz provide me with all tips and tricks i need to achieve what I want .

what I did for now :smile:

  • turn background mode for location update & uses Bluetooth & background fetch.
  • request always auth for location.
  • add text msg to info.plist file.

so let me know if I miss anything ?

Update:

AppIcon on lockScreen appear when my app close. “which mean that the phone can see the beacon” , but did start & end did not called :?


#7

:smiley:

The BeaconNotificationsManager is just a higher-level wrapper on top of ESTBeaconManager, and it does exactly what you’re saying: in didEnterRegion and didExitRegion, generates and shows a UILocalNotification. It uses static messages, but you should be able to easily modify it to fetch msgs from a server.

If you want to learn how to do background monitoring yourself, check out our tutorial:
http://developer.estimote.com/ibeacon/tutorial/part-1-setting-up/

  • turn background mode for location update & uses Bluetooth & background fetch.

You should not turn these on—you don’t need them to do background monitoring, only the “always” authorization. Having extraneous background modes enabled will get your app rejected during the review process. :scream:

Do you have your ESTBeaconManager and didEnter / Exit in the AppDelegate? Remember that if a app gets closed, all the View Controllers are deinitialized, and monitoring will stop working if you had the ESTBeaconManager in the View Controller. It’s described in greater detail in the above-mentioned tutorial. :wink:


#8

@heypiotr I just notice that I moved my delegate method to my custom class manger :stuck_out_tongue: which I declare it in viewController. Thx for mention that :wink:

So , for now Monitoring work in background/foreground and when the app closed .“didEnterRegion/didExitRegion”

Ranging work online when app in foreground and in background just for 10sec or less , but not when the app closed :smile: “didRangeBeacons”

let know if I got it wrong or misunderstand.


#9

That’s all good. Ranging only works when the app is running—either in the foreground, or in the background. And by default, when you leave the app, it transitions to the background for a few seconds (basically, iOS gives it time to save data) before being suspended, and that’s when ranging stops.

Then, if monitoring wakes the app and delivers the “enter” or “exit” event, it also run in the background for a few seconds (and ranging will work too), before it goes back to sleep (and ranging will stop working again).

Hope this makes sense (:


#10

I got it :smiley: but I faced another problem here when “enter” and “exit” event it return CLBeaconRegion which have null major&minor in my case because I thought it will return the beacon region not the region I start monitoring ??

what i’m trying to do , to solve this issue is start ranging when “enter” to get the beacon in range and send local notification depend on this beacon major&minor. but in my case sometimes there are 10 beacons at the same location which is really bad idea to follow this solution.

I found out that I can move to Eddystone implementation ? does that help ? or give me more option , or it will be the same ?

@heypiotr sorry for asking too many question and unrelated to the main question but I found out you are the only one who keep answer my questions :stuck_out_tongue:


#11

Ha, no worries man, I’m always happy to help. :heart: beacons! :wink: (That’s why I’m an evangelist I guess.)

So yeah, the thing with null major & minors is unfortunately a feature, not a bug. In iOS, if you startMonitoring for a region with just the UUID, then if enter happens, you won’t know which beacon exactly triggered the event.

One option is to monitor for UUID+major+minor, i.e., essentially for each individual beacon. If you define the region for monitoring this way, then in didEnter/didExit, you’ll have complete information. The downside: in iOS, you can only monitor for max 20 regions at a time.

Option #2 is the thing you already mentioned, i.e., do ranging when enter happens, and based on that try to figure out which beacon triggered the event. Like you noticed, it’s not always easy, as you might have a few beacons in range. But in most real-world use cases, this actually works really well: e.g., ranging tells you there are three beacons nearby, you take a look the their majors/minors, and you know that these are all entrance/lobby beacons, and thus decide to show a “hello” notification.

Eddystone at this time doesn’t have a “monitoring” option, only “scanning,” which is similar to iBeacon ranging.


#12

I moved a post to a new topic: Background monitoring doesn’t work on iOS 9