回答
当您单击不允许按钮
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
将kCLAuthorizationStatusDenied
异常调用。你可以写在里面。
另请参考:
kCLAuthorizationStatusNotDetermined = 0, // User has not yet made a choice with regards to this application
kCLAuthorizationStatusRestricted, // This application is not authorized to use location services. Due
// to active restrictions on location services, the user cannot change
// this status, and may not have personally denied authorization
kCLAuthorizationStatusDenied, // User has explicitly denied authorization for this application, or
// location services are disabled in Settings
kCLAuthorizationStatusAuthorized // User has authorized this application to use location services
实施例:
如果上用户点击允许然后
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[self refreshYourView];
}
如果点击不允许
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
if ([error code]== kCLAuthorizationStatusDenied)
{
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"User has clicked don't allow button." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
编辑
备用:您可以显示一个警报,要求用户允许通过启用位置服务从Settings
进行位置访问。在您的应用程序
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
打开设置应用:
您可以在iOS 5.0和更高版本使用。
我在应用程序中这样做了两次。一旦进入appdelegate,然后进入我有mapview的控制器之一。如果用户在appdelegate CLLocationManager警报中选择“确定”,则应用程序不应在ma控制器内提示此警报。但是,如果用户选择不允许在开始,应用程序应该在地图控制器内提示此警报。这个怎么做? – Nitish 2012-02-02 08:55:45
@Nitish:当用户选择不允许并在地图控制器中检查该标志时设置一个标志。如果标志为假,则请求用户允许。 – Maulik 2012-02-02 09:00:51
这不是我所要求的。如果用户选择不允许在应用程序启动时,CLLocationManager应该在地图控制器中提示相同的警报。如果用户在开始时选择了“确定”,则地图控制器中不应出现警报。 – Nitish 2012-02-02 09:03:55
实施CLLocationManagerDelegate Protocol
的LocationManager:didChangeAuthorizationStatus:
告诉该应用程序的授权状态改变的委托。
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
参数
经理
The location manager object reporting the event.
状态
The new authorization status for the application.
讨论
这种方法被称为每当应用程序的能力,以使用位置SERVIC es变化。 可能会发生更改,因为用户允许或拒绝为您的应用程序或整个系统使用位置服务。
- 1. 哪个按钮,在警报视图
- 2. ActionListener如何知道按下了哪个按钮?
- 3. Xamarin Grid如何知道哪个按钮被按下
- 4. 如何知道在Node.js中按下了哪个'Submit'按钮
- 5. 如何知道哪个按钮被按下?
- 6. Android的 - 按钮侦听知道哪个按钮被点击
- 7. 如何知道点击了哪个按钮
- 8. 我如何知道哪个按钮在flex中单击?
- 9. 如何知道选择了哪个单选按钮?
- 10. 在WebView中,如何知道哪个按钮被点击?
- 11. 如何知道在ListView中单击了哪个按钮
- 12. 如何知道winform c#中点击了哪个按钮?
- 13. 如何知道点击了哪个按钮?
- 14. GridView中的按钮:我如何知道哪个项目?
- 15. 如何知道哪个按钮回传页面?
- 16. 按钮和警报?
- 17. 使事件的多个按钮,并知道被点击了哪个按钮
- 18. 知道在哪个单元格中选择了哪个按钮
- 19. 使用切换按钮设置报警通知 - Android
- 20. 知道在Javascript中按下哪个按钮
- 21. 知道哪个按钮被按下了! GTK
- 22. JavaScript:如何在按下两个按钮后得到警报
- 23. 如何使警报按钮长按手势?
- 24. 如何使用单选按钮创建警报对话框?
- 25. 如何点击按钮并使用jQuery弹出警报消息
- 26. 警报视图按钮
- 27. 警报消息按钮
- 28. 按钮警报中的多个参数?
- 29. 带2个按钮的警报
- 30. 甜警报2和javascript:如何使一个甜蜜的警报按钮,当按下
为什么你不检查你是否有权访问用户的位置?如果你这样做,他选择确定。 – Kheldar 2012-02-02 08:45:34