簡體   English   中英

ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError

[英]ALAssetsLibrary ALAssetsLibraryAccessUserDeniedError

當您第一次嘗試訪問用戶的 ALAssetsLibrary 時,操作系統將向他們顯示一個詢問權限的對話框。 如果他們不允許這樣做,則將調用 failureBlock 並將在將來始終調用。 有沒有辦法再次強制提示這個授權請求?

我注意到在地圖應用程序中,他們通知用戶 go 到設置應用程序以通過按鈕打開位置服務。 但是,我不知道以編程方式打開“設置”應用程序。 我應該只顯示有關如何打開位置服務的說明嗎?

您無法以 Apple 批准的方式打開設置應用程序。 您可以期望的最好的方法是捕獲錯誤,然后顯示 UIAlertView 或其他視圖,其中包含有關如何執行此操作的說明。 查看 Dropbox 應用程序的最新版本,了解它們如何指導用戶。

當您嘗試從您的代碼訪問庫時,您可以使用錯誤處理程序來捕獲錯誤並顯示警報,指定用戶要做什么。

例子

failureBlock:^(NSError *error) {
    // error handling
    if (error.code == ALAssetsLibraryAccessGloballyDeniedError) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" 
            message:@"Error loading image... \nEnable Location Services in 'Settings -> Location Services'." 
            delegate:self cancelButtonTitle:@"OK" 
            otherButtonTitles:nil, nil];
        [alert show];
    } else if (error.code == ALAssetsLibraryAccessUserDeniedError) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" 
            message:[NSString stringWithFormat:@"Error loading image... \nEnable Location Services in 'Settings -> Location Services' for %@.", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]] 
            delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Error loading image..." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
}

暫無
暫無

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

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