【发布时间】:2015-02-15 17:50:30
【问题描述】:
我调试了一整天,委托确实被调用了。
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
这是我调用监视器的标准代码。使用 CoreLocation.framework。
[locationManager startMonitoringForRegion:geofence];
并在我的 plist 中注册了这些。
<key>NSLocationAlwaysUsageDescription</key>
<string>Lugang</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Lugang</string>
启用后台应用刷新,但我没有在其中看到我的应用。
我曾尝试在 LocationManager 的实例中打印我的受监控区域,并且有我的受监控区域。
NSLog(@"%@" ,locationManager.monitoredRegions);
并且 regionMonitoringAvailable 为真。
NSLog(@"%d" , [CLLocationManager regionMonitoringAvailable] );
在 iOS 8 中,我要求 requestAlwaysAuthorization
[locationManager requestAlwaysAuthorization];
我尝试了三种状态,前台应用,后台应用,应用未激活。这些状态都没有调用。
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
没有发现任何错误。
我试过了
[locationManager requestStateForRegion:geofence];
工作正常。
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
确实在我的 requestStateForRegion 中触发。
我不知道是什么让 didEnterRegion 没有被调用,我知道在 iOS 7 及更高版本的设备上工作,但我现在没有这样的设备来作证。
也许 requestStateForRegion 可以满足我的要求,但我仍然无法弄清楚 DidEnterRegion 是如何不起作用的。而且这些都不会触发任何错误消息来告诉开发人员进行调试。
【问题讨论】:
标签: ios objective-c cllocationmanager