我整天调试了一下,代理人根本没有接到电话。
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
好吧,这是我需要监视器的标准代码。使用CoreLocation.framework。
[locationManager startMonitoringForRegion:geofence];
并将它们注册到我的列表中。
<key>NSLocationAlwaysUsageDescription</key>
<string>Lugang</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Lugang</string>
启用后后台应用程序刷新,但是我没有看到我的应用程序。
我曾尝试在LocationManager实例中打印我的monitoredRegions,并且有我的受监视区域。
NSLog(@"%@" ,locationManager.monitoredRegions);
并且regionMonitoringAvailable为true。
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是如何工作的。这些都不会触发任何错误消息来告诉开发人员进行调试。
我遇到同样的问题,以下是我遵循的步骤并取得成功。
在中添加地理围栏数组数据之后locationmanager
。使用下面的代码相同。
for (CLRegion *monitored in [locationManagerGeofence monitoredRegions])
{
[locationManagerGeofence stopMonitoringForRegion:monitored];
}
self.geofencesArray = [NSMutableArray arrayWithArray:[self buildGeofenceData]];
if([CLLocationManager regionMonitoringAvailable])
{
for (CLRegion *region in self.geofencesArray)
{
[locationManagerGeofence startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
}
}
else
{
[BB_Global displayAlertWithTitle:@"" message:@"This app requires region monitoring features which are unavailable on this device."];
}
使用下面的委托检查您开始监视的区域。
-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
NSLog(@"Started monitoring %@ region", region.identifier);
}
将这两个委托方法用于地理围栏。1)DidEnter
2)DidExit
DidEnter
和DidExit
方法中实现本地通知,因此无需调试。一旦调用您的方法,该时间本地通知就会触发。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句