2016-01-29 236 views
2

對於測試,我試圖重新創建系統的「請求訪問」彈出體驗。PHPhotoLibrary請求授權,不請求

更新:
在iOS 11下,刪除應用程序後,系統彈出窗口將再次顯示。


(前面的問題)

第一次應用程序運行(與時間),系統彈出顯示,請求訪問。之後,甚至不刪除應用程序,重新啓動設備將再次觸發該彈出窗口。

換句話說,設備'記住'用戶請求,並且無法重置它。

下面的代碼:

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 

    switch (status) { 
     case PHAuthorizationStatusAuthorized: 
      NSLog(@"PHAuthorizationStatusAuthorized"); 
      break; 

     case PHAuthorizationStatusDenied: 
      NSLog(@"PHAuthorizationStatusDenied"); 
      break; 
     case PHAuthorizationStatusNotDetermined: 
      NSLog(@"PHAuthorizationStatusNotDetermined"); 
      break; 
     case PHAuthorizationStatusRestricted: 
      NSLog(@"PHAuthorizationStatusRestricted"); 
      break; 
    } 

}]; 

當訪問是關閉的設置,它讓印刷 「PHAuthorizationStatusDenied」。但不出現任何彈出。立即返回。

有人建議給plist添加'Bundle display name'。嘗試它沒有用,價值爲空,$(PRODUCT_NAME)和不同的字符串。

已清理的項目,刪除了DrivedData(並且每次從模擬器中刪除應用程序)。沒有運氣。

更多信息:

蘋果示例代碼「SamplePhotosApp」,一旦你關閉的設置照片訪問崩潰。

回答

1

經過進一步閱讀,這似乎是設計。

從蘋果:

此方法始終返回立即。如果用戶先前有 授予或拒絕了照片庫訪問權限,則在調用時它會執行 處理程序塊;否則,它會顯示警報,並且僅在用戶響應警報後才執行該塊。

說'如果用戶提示一次,此方法總是立即返回''。之後,它不會再顯示請求。似乎沒有辦法(但一些自定義消息)再次使用系統消息。

+0

請在這裏看看我的答案: http://stackoverflow.com/questions/26595343/determine-if-the-access-to-photo-library-is-set-or-not-ios-8/38395022#38395022 –

+0

從鏈接的答案中,解決方法是更改​​包標識符。似乎問題仍然存在;也就是說,一旦寫入了應用程序的軟件包ID,就無法「重置」其應用程序的軟件包ID,因爲缺少完整的設備重置。當然,在模擬器上,刪除設備會做到這一點。 – bauerMusic

0

重要的是將此添加到您的應用Info.plist文件。 「隱私 - 圖片庫使用說明」

我使用過這樣的內容: 「用於訪問照片庫中的照片。」

此說明將顯示在請求訪問警報框中。可以本地化,如果你想。

+ (void)imageLibraryCheckAccess:(UIViewController *)presenting 
         handler:(void (^)(PHAuthorizationStatus status))handler 
{ 
     PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; 
     if (status == PHAuthorizationStatusNotDetermined) { 
       [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { 
         if (status != PHAuthorizationStatusAuthorized) { 
           if (handler != nil) 
             handler(status); 
           NSString *title = NSLocalizedStringWithDefaultValue(@"photo.library.access.disabled.alert.title", 
                        @"Localizable", [NSBundle mainBundle], 
                        @"Photos access", @"Alert title."); 
           NSString *text = NSLocalizedStringWithDefaultValue(@"photo.library.access.disabled.alert.text", 
                        @"Localizable", [NSBundle mainBundle], 
                        @"You explicitly disabled photo library access. This results in inability to work with photos.", 
                        @"Alert text."); 
           [self alertWithPresenting:presenting title:title text:text buttons:@[[L10n okButton]] 
                handler:nil]; 
         } else if (status == PHAuthorizationStatusAuthorized) { 
           if (handler != nil) 
             handler(status); 
         } 
       }]; 
     } else if (status != PHAuthorizationStatusAuthorized) { 
       if (handler != nil) 
         handler(status); 
       NSString *title = NSLocalizedStringWithDefaultValue(@"photo.library.access.notauthorized.alert.title", 
                    @"Localizable", [NSBundle mainBundle], 
                    @"Photos access", @"Alert title."); 
       NSString *text = NSLocalizedStringWithDefaultValue(@"photo.library.access.notauthorized.alert.text", 
                    @"Localizable", [NSBundle mainBundle], 
                    @"Photo library access is disabled. Please check the application permissions or parental control settings in order to work with photos.", @"Alert text."); 
       [self alertWithPresenting:presenting title:title text:text buttons:@[[L10n okButton]] 
            handler:nil]; 
     } else if (status == PHAuthorizationStatusAuthorized) { 
       if (handler != nil) 
         handler(status); 
     } 
} 

這裏是我如何使用它:

[YourClassName imageLibraryCheckAccess:self handler:^(PHAuthorizationStatus status) { 
     if (status == PHAuthorizationStatusAuthorized) { 
     } 
}]; 

祝你好運!

+0

我同時擁有'隱私 - 圖片庫使用說明和隱私 - 圖片庫添加使用說明「(全新,在iOS 11下)。應用程序只會在沒有它們的情況下崩潰問題是觸發第一個系統彈出窗口。現在已在iOS 11下解決。系統將在刪除應用程序後再次請求權限。 – bauerMusic

+0

@bauerMusic明白了,似乎我沒有完成閱讀你的問題,並跳過去回答它。 ))我應該刪除帖子還是仍然有用? –

+0

由您決定。我想刪除整個帖子(因爲它不再相關),但會留下記錄。謝謝! – bauerMusic