iOS 9.1 中的"This app does not have access to your photos and video"



我有一个单页应用程序,用户可以点击图像,ImagePickerController显示用于从相机胶卷中挑选图像。

当包含在基于Tab视图控制器的更大的项目相同的代码,我得到错误"此应用程序无法访问您的照片和视频"。

我也试图包括"隐私-照片库使用说明"在info.plist,但没有运气。有人遇到过这个问题吗?

你检查过苹果设置>隐私>照片中的隐私设置了吗?iOS应该在首次使用时征求许可。如果用户拒绝,您所能做的就是告诉用户进入设置并允许访问。我猜这个设置对你来说是关闭的。

你可以在应用程序中检查授权状态。我用Objective C编程,我使用的是iOS 8+类phphotollibrary,但也许下面的代码会给你一些想法。(也有一些"ShowMessage"psuedo代码)

- (void) loadView {
    [self continueWithStatus: [PHPhotoLibrary authorizationStatus]];
}
- (void) continueWithStatus: (PHAuthorizationStatus) status {
    if (status == PHAuthorizationStatusRestricted)  ShowMessage "Access to photo library is restricted.";  
    else if (status == PHAuthorizationStatusDenied) ShowMessage "You need to enable access to photos.  Apple Settings > Privacy > Photos.";
    else if (status == PHAuthorizationStatusNotDetermined) {
        [PHPhotoLibrary requestAuthorization: ^(PHAuthorizationStatus status) {
            dispatch_async (dispatch_get_main_queue(), ^{   // continue work on main thread
                [self continueWithStatus: [PHPhotoLibrary authorizationStatus]];
            });
        }];
    }
    else [self startAssetRetrieve];
}

谢谢你的指导。我使用上述逻辑并创建了以下swift代码:

@IBAction func selectImageFromPhotoLibrary(sender:
 UITapGestureRecognizer) {
    authHandler(PHPhotoLibrary.authorizationStatus()) 
}
func authHandler(status: PHAuthorizationStatus) {
    switch status {
    case .Authorized:
        startAssetRevrival()
    case .Denied:
        print("denied")
    case .NotDetermined:
        print("not determined")
        PHPhotoLibrary.requestAuthorization(f)
    case .Restricted:
        print("restricted")
    }
  }
  func f(status: PHAuthorizationStatus){
    dispatch_async(dispatch_get_main_queue()) {
        self.authHandler(status)
    }
 }
 func startAssetRevrival() {
    let imagePickerController = UIImagePickerController()
    // Only allow photos to be picked, not taken.
    imagePickerController.sourceType = 
        UIImagePickerControllerSourceType.PhotoLibrary
    // Make sure ViewController is notified when the user picks an
       image.
    imagePickerController.delegate = self
    presentViewController(imagePickerController, animated: true,
    completion: nil)
}

现在我看到状态从未确定开始,然后是拒绝。在隐私设置中,我没有看到我的应用程序名称。

相关内容

最新更新