gpt4 book ai didi

ios - iOS 8 中的 didEnterRegion - 区域监控

转载 作者:可可西里 更新时间:2023-11-01 05:28:05 24 4
gpt4 key购买 nike

我正在为区域监控编写原型(prototype)类型。下面是我的一组代码

        self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager requestWhenInUseAuthorization];//commented for iOS 7

这就是我创建 locationManager 的方式

在plist中,

    <key>NSLocationAlwaysUsageDescription</key>
<string>Location is required to find out where you are</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is required to find out where you are</string>

然后

-(BOOL) checkLocationManager
{
if(![CLLocationManager locationServicesEnabled])
{
[self showMessage:@"You need to enable Location Services"];
return FALSE;
}
if(![CLLocationManager isMonitoringAvailableForClass:[CLRegion class]])
{
[self showMessage:@"Region monitoring is not available for this Class"];
return FALSE;
}
if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ||
[CLLocationManager authorizationStatus] == kCLAuthorizationStatusRestricted )
{
[self showMessage:@"You need to authorize Location Services for the APP"];
return FALSE;
}
return TRUE;
}

我正在检查那些条件

-(void) addGeofence:(NSDictionary*) dict
{

CLRegion * region = [self dictToRegion:dict];
[locationManager startMonitoringForRegion:region];
}
- (CLRegion*)dictToRegion:(NSDictionary*)dictionary
{
NSString *identifier = [dictionary valueForKey:@"identifier"];
CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];

if(regionRadius > locationManager.maximumRegionMonitoringDistance)
{
regionRadius = locationManager.maximumRegionMonitoringDistance;
}

NSString *version = [[UIDevice currentDevice] systemVersion];
CLRegion * region =nil;

if([version floatValue] >= 7.0f) //for iOS7
{
region = [[CLCircularRegion alloc] initWithCenter:centerCoordinate
radius:regionRadius
identifier:identifier];
}
else // iOS 7 below
{
region = [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
radius:regionRadius
identifier:identifier];
}
return region;
}

这组代码在 iOS 7 上完美运行。

但是当我在 iOS 8 中运行相同的程序时,当我开始监视时,将调用委托(delegate)方法 didStartMonitoringForRegion。但是当我进入该区域时,didEnterRegion 从未被调用。

对于 iOS 8,有什么我应该特别注意的吗?

最佳答案

区域监控需要用户授权始终。这是 iOS8 的新功能。

关于ios - iOS 8 中的 didEnterRegion - 区域监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30365637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com