ALAssetsGroup numberOfAssets returning 0 with photo library on iPhone that was upgraded with Photos

308 views Asked by At

I have an app that displays a list of photo albums to the user so they can select photos inside them and upload them to a server. That's all good and solid, but one person who upgraded their Mac and iPhoto library to Photos has reported that when they now use the app, some of their photo albums on their iPhone and iPad say "0 photos" when these albums worked before the upgrade.

I just enumerate the asset group (doing error checking along the way) and build a UITableViewCell with the title and number of photos with a thumbnail. This has been working for four years, and I just upgraded the code to Swift. Before the Photos upgrade, there were no reports of issues with the older Obj C code or the newer Swift code. I couldn't find anything in the release notes relevant to this issue.

If you look at an upgraded photo library in Photos app on the iPhone, albums are now in a folder called "iPhoto Albums". Those are the ones with the random problems.

The code below pulls the group from the premade array, sets the filter to only photos and gets the number of photos.

Code to pull thumbnail and title isn't listed because it always works and isn't relevant to the problem.

Also, it's always the same albums that this happens with. Apple documentation doesn't state anything about numberOfAssets() except that it's based on the filters. Filter is valid, and affected albums have been verified to contain images and no videos.

Any ideas on why this is happening would be much appreciated.

    let assetGroup = assetsGroup[indexPath.row] as! ALAssetsGroup
    assetGroup.setAssetsFilter(ALAssetsFilter.allPhotos())
    let photoCount = assetGroup.numberOfAssets()
1

There are 1 answers

1
matt On

My guess, and it is just a guess, is that your ALAsset-based code is dead.

Assets Library framework has been replaced by Photo Kit - and there is a reason for that. The whole point of Photo Kit is to prepare you for the very different reality where photos are cloud-based and the Photos app on the phone and the Photos application on the Mac cooperate through the cloud in new ways. You should have started dealing with this back in June 2014, when Photo Kit came out; now the Photos application on Mac has become reality, and that reality has struck your app.

Thus I would hypothesize that you will probably get nowhere with this problem until you replace your entire Assets Library approach to dealing with the photo library to an approach based on Photo Kit. Of course I could be wrong, but my best advice at the very least would be to do a rewrite of your app using Photo Kit and see whether it does in fact help.