【发布时间】:2013-02-08 06:10:12
【问题描述】:
我想在用户按下“不允许”时打开一个弹出窗口“应用程序想使用您当前的位置”。有什么委托方法吗??
【问题讨论】:
标签: iphone ios objective-c geolocation
我想在用户按下“不允许”时打开一个弹出窗口“应用程序想使用您当前的位置”。有什么委托方法吗??
【问题讨论】:
标签: iphone ios objective-c geolocation
Don't you dare reading the documentation...
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
if (status == kCLAuthorizationStatusDenied) {
// FA1LZ
}
}
【讨论】:
检查locationManager:didFailWithError: 和locationManager:didChangeAuthorizationStatus: 的CLLocationManagerDelegate。
【讨论】:
首先需要获取当前位置。阅读此documentation 以获取当前位置。
并使用这个方法
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
参数:
1 - 经理
报告事件的位置管理器对象。
2 - 状态
应用程序的新授权状态。
此方法的使用
只要应用程序使用位置服务的能力发生变化,就会调用此方法。由于用户允许或拒绝为您的应用程序或整个系统使用定位服务,因此可能会发生更改。
更多信息请阅读official document
【讨论】:
您可以使用以下委托方法:
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
{
if([error code]== kCLErrorDenied)
self.locationDenied = YES;
switch ([error code]) {
// "Don't Allow" on two successive app launches is the same as saying "never allow". The user
// can reset this for all apps by going to Settings > General > Reset > Reset Location Warnings.
case kCLErrorDenied:
[appDelegate showAllowGPSLocationView];
default:
break;
}
self.locationDefined = NO;
}
当用户不允许 GPS 定位时,将调用上述委托方法。您可以使用“kCLErrorDenied”检查并处理您想做的任何事情。
这里,“showAllowGPSLocationView”是“AppDelegate”中实现的方法,用于通知用户允许GPS定位。
希望对你有所帮助。
快乐编码:)
干杯!
【讨论】: