Function didEnterRegion not being called when app didFinishLaunchingWithOptions

Here is my App Delegate code:

When the app is in background, the app let me know when the iOS device enters to the region of the beacon how can I do that?

class AppDelegate: UIResponder, UIApplicationDelegate, ESTBeaconManagerDelegate {

    var window: UIWindow? 
    var mbeaconManager: ESTBeaconManager!

    let mbeaconRegion = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D"), major: 27047, minor: 31239, identifier: "rangedRegion")
 
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        ESTCloudManager.setupAppID("proximityfirstapp", andAppToken: "adee766ebf268e678965c9bd1a0cf6e6")
    
      
        let userNotificacionTypes = UIUserNotificationType.Badge | UIUserNotificationType.Sound
        let notificationSettings = UIUserNotificationSettings(forTypes: userNotificacionTypes, categories: nil)

        application.registerUserNotificationSettings(notificationSettings)
        application.registerForRemoteNotifications()
        
        mbeaconManager = ESTBeaconManager.new()
        mbeaconManager.delegate = self
        mbeaconManager.requestAlwaysAuthorization()
        
        window = UIWindow(frame: UIScreen.mainScreen().bounds)
        
        window?.rootViewController = ViewController.new()
        
        window?.makeKeyAndVisible()
        
        mbeaconManager.startMonitoringForRegion(mbeaconRegion)
        mbeaconManager.startRangingBeaconsInRegion(mbeaconRegion)
        mbeaconRegion.notifyEntryStateOnDisplay = true
        mbeaconRegion.notifyOnEntry = true
        mbeaconRegion.notifyOnExit = true
        

        return true
    }

   
    func beaconManager(manager: AnyObject!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
        println("autorizado")
    }

    func beaconManager(manager: AnyObject!, didStartMonitoringForRegion region: CLBeaconRegion!) {
        println("sta monitoreando")
        println(region)
        
    
    }
    
    func beaconManager(manager: AnyObject!, didEnterRegion region: CLBeaconRegion!) {
      
        println("entrando")
        if region.identifier == "rangedRegion" {
        
}

Looks good, with this setup monitoring should work even if the app is not running, and trigger the “enter” event if you come in range of a beacon.

hey, It doesn´t work like that. I want to present a local notification, but these methods doesn´t seem called, I had look through your documentation but it doesnt work for me. You dont have extra code in github or you cannot send me an example of code where these methods are being implemented?

You can go to cloud.estimote.com, the “Apps” section, add an app and use the “Notification” template we have to see the example implementation.

You can also follow our iBeacon tutorial to learn how to do monitoring:
http://developer.estimote.com/ibeacon/tutorial/part-1-setting-up/
http://developer.estimote.com/ibeacon/tutorial/part-2-background-monitoring/

Do you have a corresponding NSLocationAlwaysUsageDescription entry in the Info.plist file? Can you implement the didDetermineState delegate too and see if this one is being called?

Thanks you heypiotr help me solving it.

Hey, now I have another issue, the methods didEnter/didExitRegion are called and I can see the localNotifications. I will use the beacons in a store, but the thing is that they are called constantly if the device moves through the store. How can I make to only fire those methods exclusively when the client enter or exit the store? How to make a condition to restrict calling the methods when the client is inside the store?

That’s a good question, and unfortunately, not a trivial problem.

A few ideas:

  1. Reduce the broadcasting range of the beacon to the minimum value, so that the enter/exit only triggers when the client is at the door. Now, when the customer comes in for the first time, it’ll trigger an “enter” = “I’m entering the store,” and then once they move past the door further into the store, there’ll be an “exit” = “I’ve entered the store.” Then, they leave the store, approach the door = another “enter” = “I’m about to leave the store,” followed by another “exit” = "I’ve exited the store.

  2. Put one beacon at the door (let’s call it A), and another further inside the store (B). When the customer enters the store, it’ll first “enter” the beacon A, and then “enter” the beacon B—you’ll know they’ve entered the store. When they leave, they’ll first “exit” the beacon B, and then “exit” the beacon A. You’ll know they’re leaving the store.

  3. Combine beacons + regular geofencing. Beacons inside the store to quickly trigger an “enter” when they enter the store. And a CLRegion geofence around the store which will trigger an “exit”—might be a bit more delayed than an “exit” from a CLBeaconRegion, but will have much less chance of yielding a false “exit.”