CLLocationManager didEnterRegion: with iBeacon while app is suspended

一世执手 提交于 2019-11-27 18:59:25

问题


I'm trying to wake up my app (relaunch it) when it enters my defined beacon region but I just can't get it to work. This are the steps and code I'm using.

  1. Set "Location updates" Background Mode to YES.
  2. Monitor my CLBeaconRegion

    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"EBEFD083-70A2-47C8-9837-E7B5634DF524"];
        beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"daRegion"];
        beaconRegion.notifyEntryStateOnDisplay = NO;
        beaconRegion.notifyOnEntry = YES;
        beaconRegion.notifyOnExit = YES;
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        [self.locationManager startMonitoringForRegion:beaconRegion];
    
  3. Implement delegate methods

    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region;
    - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
    

Anything that I might be missing? I have read the documentation, blog posts, forums and nothing seems to work. This is one of the websites I read, and this is the other.


回答1:


The comment "I just can't get it working when the app is killed" is critical.

If you use the iOS7 app switcher to kill an app (e.g. by swiping up on the app icon), then you will not be able to re-launch the app in the background upon entering or leaving an iBeacon region. This is by design -- if the user doesn't want the app running, then Apple thinks code should not be able to make it re-launch. See this thread.

Fortunately, users don't typically do this. For testing purposes, if you want to completely stop an app, don't do this. Reboot your phone instead. (Note, however, that it takes a minute or so after boot before you can detect iBeacons.)

EDIT 2014/03/10: This behavior has changed as of the release of iOS 7.1. Killing an app from the task switcher no longer stops it from detecting iBeacons in the background.



来源:https://stackoverflow.com/questions/21124528/cllocationmanager-didenterregion-with-ibeacon-while-app-is-suspended

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!