Notify iBeacon when the application is not running

I managed to create an iBeacon that triggers a local push notification on my iPhone when the beacon is in range. It works great when the application is in the background.

My question is: can I initiate a notification even if the application does not work, not even in the background?

I thought it was possible, but I'm not sure. If so, how can I do this?

Thank!

+57
ios ios7 ibeacon core-bluetooth
01 Oct '13 at
source share
6 answers

Yes, this is possible and should be automatic.

After you create a CLBeaconRegion and start tracking it, location services will track whether your phone is in or out of the region, even if your app is down. If the application does not work during the transition, iOS will launch your application in the background for several seconds to call the appropriate CLLocationManagerDelegate methods.

I figured out the above behavior by experimenting with my own application, but also witnessed it using the Apple AirLocate sample program. With AirLocate, if you set up a monitoring region, restart the phone, AirLocate will still provide a local notification as soon as the phone enters the region.

Use caution when checking this, because sometimes it takes up to 4 minutes after turning iBeacon on / off before iOS recognizes the state transition of the region. EDIT . On iPhone 5, applications typically use hardware acceleration to detect beacons within seconds, and if hardware acceleration is not available, this can take up to 15 minutes.

EDIT: As in iOS 8, you need to make sure that you call and successfully receive locationManager.requestAlwaysAuthorization() as locationManager.requestWhenInUseAuthorization() , only beacons will be detected in the foreground.

I posted a detailed discussion of how it all works in this blog post.

+64
Oct 02 '13 at 1:47
source share
โ€” -

OK. I got this to work correctly and experiment with it, and here is the answer. This is what you need to do to get your application to be called when crossing the border of the beacon area after the application has been interrupted (if your application is working correctly in the foreground):

  • You must implement the CLLocation delegate inside your AppDelegate.m module . This delegate is what iOS calls, so if you donโ€™t have the CLLocation delegate CLLocation in AppDelegate.m , you wonโ€™t be able to respond to iOS when your application was interrupted. This is an example of an Apple AirLocate application.

So, inside AppDelegate.m you need the following (you also need to set the CoreLocation.h link):

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. // This location manager will be used to notify the user of region state transitions when the app has been previously terminated. self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; return YES; } 
  1. Inside AppDelegate.m you need to implement the locationManager didDetermineState method, for example:

     -(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{ UILocalNotification *notification = [[UILocalNotification alloc] init]; if(state == CLRegionStateInside) { notification.alertBody = [NSString stringWithFormat:@"You are inside region %@", region.identifier]; } else if(state == CLRegionStateOutside) { notification.alertBody = [NSString stringWithFormat:@"You are outside region %@", region.identifier]; } else { return; } [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; } 

-> So, if your application was interrupted (it should run at least ONCE) when the device goes to the border of the beacon that you control, iOS will call your application and call the locationManager:didDetermineState in your AppDelegate.m module. Inside this method, you can configure and call presentLocalNotificationNow. If your application is NOT in the foreground when this happens, iOS will present a notification on the screen, even if it is locked. Then the user will need to call the application for more information.

I am pretty sure that the memory pressure has nothing to do with it. In addition, setting notifyEntryStateOnDisplay has nothing to do with this problem. The notifyEntryStateOnDisplay setting notifyEntryStateOnDisplay used only when the user turns on the display of the iOS device (ie, falls into the "home" or upper left button). If the user does this, and notifyEntryStateOnDisplay is TRUE , and the INSIDE device is the area of โ€‹โ€‹the beacon that you are tracking, THEN you will receive a notification on the display at this time. If this property is set to FALSE , you will not.

Of course, for this material to work correctly, you need to run iOS 7.1.

For more information, visit the Apple documentation

+18
Mar 19 '14 at 19:04
source share

You need to switch notifyEntryStateOnDisplay = YES for CLBeaconRegion so that the system wakes your iBeonon login / logout application.

But there is one difficult part. If your application is not running, the system will only wake your entry / exit application with a beacon if your application was interrupted earlier due to pressure in the system memory. If the user killed the application by checking it in the task, the system will not wake your application. To test this behavior, run the application, place it in the background, and then run several memory-consuming applications in sequence. I launched several 3D games before my application crashes due to memory pressure.

+9
Feb 06 '14 at 0:25
source share

Just upgrade your iOS version to 7.1 and set "notifyEntryStateOnDisplay = YES" and it should work like a charm, even if your application doesn't work. I had this problem before, but it was fixed after I made this update! Enjoy ..

+6
Mar 11 '14 at 16:14
source share

The only way I was able to do this work is to monitor major location changes that seem to do the trick. Be careful, I have not tested this for the entire device or use cases.

+2
Oct 26 '13 at 20:18
source share

Yes, we can present a local notification in the kill state or in the background, just follow the steps,

1) Launch the location manager using the CLLocationManager class.

 locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy=kCLLocationAccuracyBest; locationManager.distanceFilter=kCLDistanceFilterNone; 

2) Create a CLBeaconRegion as,

 CLBeaconRegion *beacon_Region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid major:mjorVa minor:minorVa identifier:identifier]; beacon_Region.notifyEntryStateOnDisplay = YES; beacon_Region.notifyOnEntry=YES; beacon_Region.notifyOnExit=YES; 

3) Implement two methods of delegation of the location manager, for example

 -didEnterRegion -didExitRegion 

The above location method will work, even your application will be killed or in the background. The system will track your beacon, and when it goes out of range, the system will run the didExitRegion method, and when it logs in, the didEnterRegion method will fire.

+1
Nov 05 '15 at 10:45
source share



All Articles