iOS 12 Beta 6: Fetching All Photos Bug

This was fine until beta 6 of iOS 12. Now fetching "All Photos" is not happening properly.


For the last photo, it shows a random photo from the middle. All Photos is loaded improperly.


Fetching all photos:

let allPhotosOptions = PHFetchOptions()
self.assetsFetchResults = PHAsset.fetchAssets(with: allPhotosOptions)
self.assetCollection = PHAssetCollection.transientAssetCollection(withAssetFetchResult: self.assetsFetchResults!, title: "All Photos")


Fetching Last Photo:

let allPhotosOptions = PHFetchOptions()
let assetsFetchResults = PHAsset.fetchAssets(with: allPhotosOptions)
if assetsFetchResults.count == 0 {
 self.showCameraRollEmptyAlert()
 return nil
}
let asset = assetsFetchResults.lastObject


This started happening on beta 6, it was fine with previous betas.

Replies

I am also having a similar issue.


If I add a new image to the iphone, it never shows on the top but the images always come in the same order and the newest images, somewhere in the middle.

I reported this on August 7th with radar 43024953. So far no feedback.

May be an explicit sort descriptor is needed?


let allPhotosOptions = PHFetchOptions()
allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]

I tried it, but the creation date does not give the same order.

Was anyone able to resolve this issue? I'm still seeing this on iOS 12 release

I still have the issue. I had to work around it by using NSSortDescriptor for now.

This is reported under radar 43024953

I have the same... how to use NSSortDescriptor?

let allPhotosOptions = PHFetchOptions() 
allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]


This, however, is not exactly the same as stock Photos App's sorting. If you newly add an item that were created long time ago, they do not show up at the end as they should.