【发布时间】:2015-01-27 15:25:35
【问题描述】:
我有一个应用程序,我想向它添加一些基于位置的功能。它同时支持 iOS 7 和 8,但我遇到了一些问题。
我只想在用户点击某个 viewController 上的某个按钮时请求位置权限。问题是权限请求会在应用程序启动后立即出现。更准确地说,在第一个 viewController 的 ViewWillAppear 和 ViewDidAppear 函数之间。
我之前尝试过的:
-
在 plist 中有 NSLocationWhenInUseUsageDescription 键(适用于 iOS8)。 代码方面:
self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; self.locationManager.delegate = self; if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; } [self.locationManager startUpdatingLocation]; 删除 plist 键 -> 这导致 iOS8 中的弹出窗口不再出现,但在 iOS7 中仍然出现
目前,与 CoreLocation 相关的每一段代码都已被注释掉,但我仍然会看到询问我权限的对话框(仅限 iOS7)
我不知道我还能尝试什么,所以非常感谢任何一点帮助
【问题讨论】:
-
在用户按下您想要的按钮之前,不要执行任何 CLLocationManager 代码。
标签: ios objective-c core-location