ios – iBeacon:didEnterRegion和didDetermineState(CLRegionStateInside)之间有什么区别?

前端之家收集整理的这篇文章主要介绍了ios – iBeacon:didEnterRegion和didDetermineState(CLRegionStateInside)之间有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
用户进入某个地区时,我想发布通知.但是,由于同样的两个CLLocationManagerDelegate方法,我很困惑.如何正确使用这两种方法

有些人说如果应用程序在该区域启动,则需要“didDetermineState”方法来启动区域观察.

谢谢,

- (void)locationManager:(CLLocationManager *)manager
         didEnterRegion:(CLRegion *)region
{
    [self sendNotification:@"didEnterRegion"];
}

- (void)locationManager:(CLLocationManager *)manager
      didDetermineState:(CLRegionState)state
              forRegion:(CLRegion *)region
{
    switch (state) {
        case CLRegionStateInside:
         [self sendNotification:@"didEnterRegion"];
            break;
        case CLRegionStateOutside:
            break;
        case CLRegionStateUnknown:
            break;
        default:
            break;
    }
}

解决方法

苹果的 documentation for CLLocationManager状态:

The location manager calls this method whenever there is a boundary transition for a region. It calls this method in addition to calling the locationManager:didEnterRegion: and locationManager:didExitRegion: methods. The location manager also calls this method in response to a call to its requestStateForRegion: method,which runs asynchronously.

所以doEnterState应该在doEnterRegion / didExitRegion做的时候调用.另外,如果你通过requestStateForRegion显式请求状态,它将被调用.

触发此方法的另一种行为是:如果要监视已启用notifyEntryStateOnDisplay属性的区域,则只要用户手动唤醒设备,并且它们在您正在监视的区域内,就会调用方法.从the documentation

When set to YES,the location manager sends beacon notifications when the user turns on the display and the device is already inside the region. These notifications are sent even if your app is not running. In that situation,the system launches your app into the background so that it can handle the notifications. In both situations,the location manager calls the locationManager:didDetermineState:forRegion: method of its delegate object.

原文链接:https://www.f2er.com/iOS/329975.html

猜你在找的iOS相关文章