The file “IMG_----.JPG” couldn’t be opened because you don’t have permission to view it

When importing more than 1000 images in iOS9, a few images show "The file "IMG----.JPG" couldn't be opened because you don't have permission to view it. The file "IMG.JPG" couldn't be opened because you don't have permission to view it" appears for a few photos, and they cannot be imported.

The images in Photolibrary are retrieved by PHAsset.fetchAssets.

In iOS 10.3.3 or later, the same program does not cause this problem.

I checked the log to see if the URL or Asset was nil, but I didn't find anything wrong with the images that were successfully loaded.

Some of the codes we are getting are listed below.

Code Block Swift
private func _getAssetOption() -> PHFetchOptions {
    let option = PHFetchOptions()
    option.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
    option.includeAssetSourceTypes = .typeUserLibrary
    option.includeAllBurstAssets = true
    return option
}
 private func _getAssets() -> PHFetchResult<PHAsset> {
    return PHAsset.fetchAssets(with: .image, options: _getAssetOption())
}


Replies

Fortunately, there are very few iOS9 still in operation.

Did you inspect some of the file manually ?
Thanks for the reply.

First of all, the image data used is a copy of a single image to make the specified number of copies.
The same problem is also seen in iOS 10.0.1.

The files that could not be read are being investigated using the following information.
  • Data status (whether it is damaged or not)

→ I checked whether the file could be read by PhotoLibrary, and it can be opened and displayed normally.

  • The data can be opened and displayed normally.

→ When I deleted all the data except for the data that could not be read, I was able to read all the data. So I guess the problem depends on the amount of data rather than the state of the data.