- (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);
}上面是我的代码。我在模拟器中运行,没有位置,然后在调试委派项中设置了客户位置(23.126272,113.395568),它从不调用didEnterRegion ->location。有人能帮我吗?PS:我的Xcode是7.1.1,控制台日志“开始监控fkit region”
发布于 2015-11-29 22:48:46
你遗漏了一些步骤。你必须向你的info.plist添加一个条目,声明当你的应用程序在前台时,你想使用定位服务,(使用NSLocationWhenInUseUsageDescription键),然后你需要检查你是否有权限,如果你没有权限,就请求它。
在Xcode文档中搜索字符串"Requesting Permission to Use Location Services“以获取更多信息。
发布于 2016-04-18 17:20:19
在didStartMonitoringForRegion中添加此行
[self.locationManager requestStateForRegion:yourregion];https://stackoverflow.com/questions/33983541
复制相似问题