有些人说如果应用程序在该区域启动,则需要“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; } }
解决方法
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:
andlocationManager:didExitRegion:
methods. The location manager also calls this method in response to a call to itsrequestStateForRegion:
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.