Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么在授予权限后画廊中的照片不显示?_Ios_Swift_Github_Photo Gallery - Fatal编程技术网

Ios 为什么在授予权限后画廊中的照片不显示?

Ios 为什么在授予权限后画廊中的照片不显示?,ios,swift,github,photo-gallery,Ios,Swift,Github,Photo Gallery,我使用它在UICollectionView中显示用户的照片库。那里一切正常,但除了一个:如果我第一次运行它,它会询问我权限。我接受它,但在那之后我无法从画廊获得我的图像。它什么也不显示 但当我关闭应用程序并再次运行时,它可以从图库中获取我的照片。所以,这个问题在第一次发射时就出现了 谁能帮我,我怎么解决 更新 我想,这个观察者是不正确的: func photoLibraryDidChange(changeInstance: PHChange) { let changeDetails =

我使用它在UICollectionView中显示用户的照片库。那里一切正常,但除了一个:如果我第一次运行它,它会询问我权限。我接受它,但在那之后我无法从画廊获得我的图像。它什么也不显示

但当我关闭应用程序并再次运行时,它可以从图库中获取我的照片。所以,这个问题在第一次发射时就出现了

谁能帮我,我怎么解决

更新

我想,这个观察者是不正确的:

func photoLibraryDidChange(changeInstance: PHChange) {
    let changeDetails = changeInstance.changeDetailsForFetchResult(images)

    self.images = changeDetails!.fetchResultAfterChanges
    dispatch_async(dispatch_get_main_queue()) {
        // Loop through the visible cell indices
        let indexPaths = self.imagesCollectionView.indexPathsForVisibleItems()
        for indexPath in indexPaths as [NSIndexPath]! {
            if changeDetails!.changedIndexes!.containsIndex(indexPath.item) {
                let cell = self.imagesCollectionView?.cellForItemAtIndexPath(indexPath) as! ImagesCollectionViewCell
                cell.imageAsset = changeDetails!.fetchResultAfterChanges[indexPath.item] as? PHAsset
            }
        }
    }
}
所以,我授予权限,但它不显示我的照片。为此,我需要重新启动我的应用程序


如果你想要任何代码,我可以分享。但是我使用的是上面附带的github控制器。

因为当你重新启动应用程序时它可以正常工作,所以听起来你可能在显示视图控制器/集合视图的同时请求权限。问题是,一旦用户选择让你的应用程序访问他们的照片,收藏视图就不知道如何重新加载。在PHPhotoLibrary.requestAuthorization回调中,您需要告诉视图控制器/集合视图在对您的应用程序进行授权后重新加载。下面是一个小例子:

PHPhotoLibrary.requestAuthorization { status in
switch status {
case .Authorized:
   /* RELOAD COLLECTION VIEW HERE */
case .Restricted:
    <#your code#>
case .Denied:
    <#your code#>
default:
    // place for .NotDetermined - in this callback status is already determined so should never get here
    break
}
PHPhotoLibrary.requestAuthorization{中的状态
开关状态{
案例.授权:
/*在此处重新加载集合视图*/
案例.限制性:
案件.驳回:
违约:
//放置.NotDetermined-在此回调中,状态已确定,因此不应到达此处
打破
}

}

你解决了吗@约翰