OGeek|极客世界-中国程序员成长平台

标题: ios - PHPhotoLibrary requestAuthorization,不是请求 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:22
标题: ios - PHPhotoLibrary requestAuthorization,不是请求

为了测试,我试图重新创建系统“请求访问”弹出窗口体验。

更新:
iOS 11下,删除App后,会再次出现系统弹窗。


(上一个问题)

App 第一次运行时(也是唯一 次),系统弹出窗口显示,请求访问。之后,即使不删除应用程序并重新启动设备也会再次触发该弹出窗口。

换句话说,设备“记住”了用户请求并且无法重置。

代码如下:

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

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

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

}];

当设置中的访问关闭时,它会一直打印“PHAuthorizationStatusDenied”。但不显示任何弹出窗口。立即返回。

建议将“Bundle display name”添加到 plist。用空值、$(PRODUCT_NAME) 和不同的字符串尝试过,但无济于事。

清理项目,删除 DrivedData(并每次都从模拟器中删除 App)。运气不好。

更多信息:

一旦您在“设置”中关闭照片访问权限,Apple 示例代码“SamplePhotosApp”就会崩溃。



Best Answer-推荐答案


进一步阅读后,这似乎是设计使然。

来自 Apple:

This method always returns immediately. If the user has previously granted or denied photo library access permission, it executes the handler block when called; otherwise, it displays an alert and executes the block only after the user has responded to the alert.

如果用户提示一次,则说“此方法总是立即”。之后它不会再显示请求。好像没办法(不过是一些自定义消息)再用系统消息。

关于ios - PHPhotoLibrary requestAuthorization,不是请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35083401/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4