gpt4 book ai didi

ios - locationManager didExitRegion 或 locationManager didEnterRegion 从未调用

转载 作者:行者123 更新时间:2023-12-01 16:28:11 24 4
gpt4 key购买 nike

   - (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);
}

以上是我的代码。我在没有位置的模拟器中运行,然后在 Debug ->location item 中设置custome location(23.126272,113.395568) ,它从不调用 didEnterRegion delegate 。任何人都可以帮助我吗?
PS:我的Xcode是7.1.1,控制台日志“Started monitoring fkit region”

最佳答案

您缺少几个步骤。您必须在 info.plist 中添加一个条目,声明您想在应用程序处于前台时使用定位服务(使用 NSLocationWhenInUseUsageDescription 键),然后您需要检查您是否有权限,并询问如果你不这样做。

在 Xcode 文档中搜索字符串“Requesting Permission to Use Location Services”以获取更多信息。

关于ios - locationManager didExitRegion 或 locationManager didEnterRegion 从未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33983541/

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