簡體   English   中英

iOS不可靠的位置權限警報

[英]iOS Unreliable Location Permission Alert

在我們的應用中,我們要求用於顯示地圖的一個視圖上的位置許可(WhenInUse)。

如果用戶選擇禁用設備位置服務(即在設備設置中全局禁用),然后在應用程序中打開我們的視圖,則將顯示位置權限彈出窗口。 重復沖洗幾次(重新打開服務,打開應用程序,離開應用程序,關閉服務等),然后重復幾次,位置權限警報將停止顯示。

有人知道這是否是iOS中的錯誤(發生在iOS 10上)嗎?

我們可以使用自己的警報來顯示何時

CLLocationManager locationServicesEnabled = NO

但由於我們無法控制是否/何時彈出iOS位置警報,因此有時會同時出現這兩種情況,這是錯誤的UX。

任何已知的解決方案? 如果這是iOS中的錯誤,我必須向我們的質量檢查和經理解釋。

編輯:

- (BOOL)negotiateLocationServicePermission:(UIViewController *)context
{
    /* Device location service is enabled. */
    if ([CLLocationManager locationServicesEnabled])
    {
        /* App location service is already authorized. */
        if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse
            || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways)
        {
            /* App location service is authorized. Start location updates ... */
            [self startUpdatingLocation];
            return YES;
        }
        else
        {
            /* App location service not yet authorized and status is not determined (aka: first time asking for permission). */
            if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined)
            {
                /* Request the location permission from the user. */
                if ([self respondsToSelector:@selector(requestWhenInUseAuthorization)])
                    [self requestWhenInUseAuthorization]; /* iOS 8+ */
                else
                    [self startUpdatingLocation]; /* iOS 7 */
                return YES;
            }
            /* App location service not authorized and previously denied. */
            else
            {
                /* App location service permission was denied before. */
                // Show custom alert!
                return NO;
            }
        }
    }
    /* Device location service is disabled. */
    else
    {
        // Show custom alert!
        return NO;
    }
}

我不認為這是一個錯誤,這與AlertView不同。

如果用戶一次接受位置許可,則將其保存,不會再詢問他。 但是,如果禁用了位置服務,則情況將有所不同。

您可以這樣實現:

if ([CLLocationManager locationServicesEnabled]){

    NSLog(@"Location Services Enabled");

    if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
        alert = [[UIAlertView alloc] initWithTitle:@"App Permission Denied"     
                                           message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                                          delegate:nil 
                                 cancelButtonTitle:@"OK" 
                                 otherButtonTitles:nil];
        [alert show];
    }
}

因此,如果用戶從“設置”中禁用了定位服務,則警報視圖可以重定向到“設置”頁面。

這樣就不會顯示多個AlertViews。 這僅取決於您要如何處理每種情況,例如:

  • 在“設置”中啟用了定位服務,但對此應用程序的權限被拒絕
  • 在設置和授權權限中啟用了定位服務
  • 在設置中禁用了定位服務

確保處理好每種情況,然后進行測試。

我不知道是否能准確回答您的問題,希望對您的實施有所幫助。

如果我沒記錯的話,只有在authorizationStatus undetermined時才發出iOS對話框。 如果狀態被denied (當僅特定應用被拒絕或整個位置服務被禁用時),您需要發出自己的對話框,其中包含指向設置的深層鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM