2016-01-29 147 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