回答
當您單擊不允許按鈕
- (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. 如何知道哪個按鈕點擊使用this.Request.Form
- 2. 哪個按鈕,在警報視圖
- 3. Xamarin Grid如何知道哪個按鈕被按下
- 4. 如何知道在Node.js中按下了哪個'Submit'按鈕
- 5. ActionListener如何知道按下了哪個按鈕?
- 6. 如何知道哪個按鈕被按下?
- 7. Android的 - 按鈕偵聽知道哪個按鈕被點擊
- 8. gcc如何知道使用哪個庫?
- 9. 如何知道單擊的是哪個按鈕,JSP
- 10. 如何知道在vb.net中點擊了哪個命令按鈕?
- 11. 如何知道檢查哪個單選按鈕?
- 12. 如何知道哪個活動點擊了按鈕?
- 13. 我如何知道哪個按鈕在flex中單擊?
- 14. 如何知道在jquery中選擇了哪個單選按鈕?
- 15. ASP.NET如何知道哪個按鈕導致了回傳?
- 16. 如何知道winform c#中點擊了哪個按鈕?
- 17. 如何知道自定義列表中單擊哪個按鈕
- 18. 如何知道我在燒瓶中點擊了哪個按鈕?
- 19. 如何知道選擇了哪個單選按鈕?
- 20. 如何知道jquery檢查了哪個單選按鈕?
- 21. 如何知道點擊了哪個按鈕?
- 22. 如何知道哪個按鈕被點擊?
- 23. 如何知道哪個圖像按鈕,我點擊datalist
- 24. 如何知道哪個按鈕回傳頁面?
- 25. 如何知道在ListView中單擊了哪個按鈕
- 26. 如何知道我點擊了哪個表單按鈕類
- 27. 在WebView中,如何知道哪個按鈕被點擊?
- 28. 如何知道哪個按鈕提交表單的PHP
- 29. 如何知道點擊了哪個按鈕?
- 30. GridView中的按鈕:我如何知道哪個項目?
爲什麼你不檢查你是否有權訪問用戶的位置?如果你這樣做,他選擇確定。 – Kheldar 2012-02-02 08:45:34