Search code examples
iosphassetclgeocoderapple-photos

What rules do Moments album section headers follow


I'm trying to create a CollectionView that mimics the UI of the Moments album in the iOS Photos app. I'm very close to finishing it, but I'm struggling to figure out what rules Apple are using to create the label for each date/location section of photos.

I'm using the below snippet of code to fetch the location for the first asset in each section:

if let location = AssetsManager.shared.assetArray[indexPath.section][0].location {
    CLGeocoder().reverseGeocodeLocation(location, completionHandler:{(placemarks, error) in
        if placemarks != nil && error == nil && placemarks!.count > 0 {
            let placemark = placemarks![0] as CLPlacemark
        }
        ....

CLPlacemark objects have a ton of location attributes, but I cannot figure out the exact pattern that Apple are following. At times they use the "locality" attribute as the primary label, sometimes they append the "subLocality" attribute. Other times they use the "name" attribute, and occasionally append the "AdminArea" attribute. This is further complicated by further variations of this between the main label and sub-label.

Does anyone have any idea what rules their section header labels might be using?


Solution

  • I was overthinking this. It turns out the Photos app simple calls .localizedTitle and .localizedLocationNames of PHAssetCollection for the header and subHeader respectively.