CLLocationManager didEnterRegion:在应用程序暂停时使用iBeacon

Her*_*Rod 3 objective-c core-location ios bluetooth-lowenergy ibeacon

我正在尝试唤醒我的应用程序(重新启动它),当它进入我定义的信标区域但我无法让它工作.这是我正在使用的步骤和代码.

  1. 将"位置更新"背景模式设置为YES.
  2. 监控我的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];
    
    Run Code Online (Sandbox Code Playgroud)
  3. 实现委托方法

    - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region;
    - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
    - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
    
    Run Code Online (Sandbox Code Playgroud)

我可能遗失的任何东西?我已阅读文档,博客文章,论坛,似乎没有任何工作.是我读过的网站之一,是另一个.

dav*_*ung 10

评论"当应用程序被杀时我无法使其正常工作"至关重要.

如果您使用iOS7应用程序切换器来杀死应用程序(例如,通过向上滑动应用程序图标),那么在进入或离开iBeacon区域时,您将无法在后台重新启动应用程序.这是设计 - 如果用户不希望应用程序运行,那么Apple认为代码不应该能够重新启动它. 看到这个帖子.

幸运的是,用户通常不这样做.出于测试目的,如果要完全停止应用程序,请不要这样做.重新启动手机.(但请注意,启动后需要一分钟左右才能检测到iBeacons.)

编辑2014/03/10:自iOS 7.1发布以来,此行为已发生变化.从任务切换器中杀死应用程序不再阻止它在后台检测到iBeacons.

  • @herz,我很想错!我不同意这两个文件不一致.您引用的那个表示即使您的应用程序未运行,也会进行回调.这是事实,但它遗漏了应用程序必须至少运行一次以使其工作的细节.从应用切换器中杀死应用程序实际上会将您的应用程序恢复到第一次启动之前的状态.如果您对此表示怀疑,那么设置测试并尝试自己就很容易了.我很想听听你的结果! (2认同)