Ios 从未调用过locationManager DidextRegion或locationManager DienterRegion
上面是我的代码。我在没有位置的模拟器中运行,然后在Debug->location项中设置custome位置(23.126272113.395568),它从不调用didEnterRegion委托。有人能帮我吗?Ios 从未调用过locationManager DidextRegion或locationManager DienterRegion,ios,objective-c,Ios,Objective C,上面是我的代码。我在没有位置的模拟器中运行,然后在Debug->location项中设置custome位置(23.126272113.395568),它从不调用didEnterRegion委托。有人能帮我吗? PS:我的Xcode是7.1.1,控制台日志“已开始监视fkit区域”您缺少一些步骤。您必须在info.plist中添加一个条目,声明您希望在应用程序处于前台时使用定位服务(使用nslocationwhenUsageDescription键),然后您需要检查是否有权限,如果没有权限,请请求
PS:我的Xcode是7.1.1,控制台日志“已开始监视fkit区域”您缺少一些步骤。您必须在info.plist中添加一个条目,声明您希望在应用程序处于前台时使用定位服务(使用
nslocationwhenUsageDescription
键),然后您需要检查是否有权限,如果没有权限,请请求
在Xcode文档中搜索字符串“请求使用位置服务的权限”以获取更多信息。在didStartMonitoringForRegion中添加此行
- (void)viewDidLoad
{
[super viewDidLoad];
if([CLLocationManager locationServicesEnabled]){
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
CLLocationCoordinate2D companyCenter;
companyCenter.latitude = 23.126272;
companyCenter.longitude = 113.395568;
CLRegion* fkit = [[CLCircularRegion alloc] initWithCenter:companyCenter
radius:500 identifier:@"fkit"];
[self.locationManager startMonitoringForRegion:fkit];
}else{
NSLog(@"not support");
}
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"Error : %@",error);
}
- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"Region monitoring failed with error: %@", [error localizedDescription]);
}
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(nonnull CLRegion *)region
{
NSLog(@"Entered Region - %@", region.identifier);
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(nonnull CLRegion *)region
{
NSLog(@"Entered Enter Region - %@", region.identifier);
}
- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {
NSLog(@"Started monitoring %@ region", region.identifier);
}
我添加了这个密钥,模拟器要求我允许定位,但它什么都没有。所以在实际设备上尝试一下
[self.locationManager requestStateForRegion:yourregion];