swiftios13photolibrarycamera-rollphassetcollection

can't find Camera Roll album in Smart Album iOS 13


I ran into a problem. There were 15 albums for type smartAlbum in AssetCollection before iOS 13, but with iOS 13, the number became 14. Camera Roll disappeared from it. Here Code of fetching albums:

func loadAlbums() {
    var albums:[AlbumModel] = [AlbumModel]()
    let options = PHFetchOptions()
    let userAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .any, options: options)
    userAlbums.enumerateObjects { [weak self] (object: AnyObject!, count: Int, stop: UnsafeMutablePointer) in
        if object is PHAssetCollection {
            let obj: PHAssetCollection = object as! PHAssetCollection
            let fetchOptions = PHFetchOptions()
            fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
            fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)
            if let arrayAllowedTypes = self?.arrayAllowedSubtypesRawValues, arrayAllowedTypes.contains(obj.assetCollectionSubtype.rawValue) {
                let photos = PHAsset.fetchAssets(in: obj, options: fetchOptions)
                let newAlbum = AlbumModel(name: obj.localizedTitle ?? String.empty, count: photos.count, collection:obj, firstAsset: photos.firstObject)
                albums.append(newAlbum)
            }
        }
    }
    allowedAlbums = albums
    selectedAlbum = albums.first(where: { (album) -> Bool in
        album.collection.assetCollectionSubtype.rawValue == 209 // Camera roll
    })
}

and result iOS 13:

<PHFetchResult: 0x280560960> count=14
<PHAssetCollection: 0x14de1b9d0> B93E78CF-FBE8-4791-9B63-009AC9F40FCE/L0/040, title:"Panoramas", subtitle:"(null)" assetCollectionType=2/201
<PHAssetCollection: 0x14de21470> FA7600A5-2B42-4C6F-AC50-B604810BC06B/L0/040, title:"Favorites", subtitle:"(null)" assetCollectionType=2/203
<PHAssetCollection: 0x14de06aa0> 4329C50B-EE1D-494A-8585-5FC1DBFE890F/L0/040, title:"Slo-mo", subtitle:"(null)" assetCollectionType=2/208
<PHAssetCollection: 0x14de0f910> C32B141D-3BCB-4525-8EAD-A24DEE904F60/L0/040, title:"Live Photos", subtitle:"(null)" assetCollectionType=2/213
<PHAssetCollection: 0x14de1aa90> 2355B0FA-6CDD-4B59-A089-5CA2CCD059DF/L0/040, title:"Videos", subtitle:"(null)" assetCollectionType=2/202
<PHAssetCollection: 0x14de1abd0> F71FE5C0-D5CD-4417-8666-F11C85240448/L0/040, title:"Animated", subtitle:"(null)" assetCollectionType=2/214
<PHAssetCollection: 0x14de10040> 1B2B6D54-1622-4953-87BD-7FF112D3F886/L0/040, title:"Selfies", subtitle:"(null)" assetCollectionType=2/210
<PHAssetCollection: 0x14de10180> B2D3ECEE-E0D0-44E9-94F6-F9C076B7E91A/L0/040, title:"Time-lapse", subtitle:"(null)" assetCollectionType=2/204
<PHAssetCollection: 0x14de102c0> CDBCF8A4-50ED-4709-809A-BFC2C3B8BFE7/L0/040, title:"Hidden", subtitle:"(null)" assetCollectionType=2/205
<PHAssetCollection: 0x14de10400> 776A0192-C323-4932-9328-50D9C7A364FE/L0/040, title:"Portrait", subtitle:"(null)" assetCollectionType=2/212
<PHAssetCollection: 0x14de10540> 46B7DFE0-F9EA-46DA-8C51-5570E3AF37AB/L0/040, title:"Bursts", subtitle:"(null)" assetCollectionType=2/207
<PHAssetCollection: 0x14de10680> 5EF48500-3FAA-415A-800C-C160CC8D1A19/L0/040, title:"Recents", subtitle:"(null)" assetCollectionType=2/209
<PHAssetCollection: 0x14de296c0> F28207C8-9B4F-44A8-9F5B-32E6C6169B6E/L0/040, title:"Long Exposure", subtitle:"(null)" assetCollectionType=2/215
<PHAssetCollection: 0x14de29800> 4426D307-05B1-42C5-9F9B-391EA25CDDA2/L0/040, title:"Screenshots", subtitle:"(null)" assetCollectionType=2/211  

result iOS 12

<PHFetchResult: 0x280c51a80> count=15
<PHAssetCollection: 0x1057046e0> 70B8F334-A376-4EFF-B92B-E3329F97F7B1/L0/040, title:"Recently Added", subtitle:"(null)" assetCollectionType=2/206
<PHAssetCollection: 0x105749e90> DA0DDAE1-1028-469D-B700-6F52F9F375B1/L0/040, title:"Portrait", subtitle:"(null)" assetCollectionType=2/212
<PHAssetCollection: 0x10574d320> 70B0A71A-08D2-4C3C-B96E-5380CAA83A36/L0/040, title:"Slo-mo", subtitle:"(null)" assetCollectionType=2/208
<PHAssetCollection: 0x10574d440> 99DB1706-09FB-4ADD-AAF9-46CC47AEAF49/L0/040, title:"Time-lapse", subtitle:"(null)" assetCollectionType=2/204
<PHAssetCollection: 0x10574d620> 91D9696D-E4CC-46E8-AABD-E6A90D06D954/L0/040, title:"Animated", subtitle:"(null)" assetCollectionType=2/214
<PHAssetCollection: 0x10574d740> 19FA3952-F1B0-469E-82C2-A983879322E2/L0/040, title:"Screenshots", subtitle:"(null)" assetCollectionType=2/211
<PHAssetCollection: 0x10574d860> D9D5099F-FA01-4903-B611-A3484ED53FDE/L0/040, title:"Favorites", subtitle:"(null)" assetCollectionType=2/203
<PHAssetCollection: 0x10574d980> 5A27E642-D6DD-4DFE-B90E-6BD17F5C73B6/L0/040, title:"Long Exposure", subtitle:"(null)" assetCollectionType=2/215
<PHAssetCollection: 0x10574daa0> 9C5D6211-B455-419A-BB2C-59AED1F76F46/L0/040, title:"Videos", subtitle:"(null)" assetCollectionType=2/202
<PHAssetCollection: 0x10574dbc0> 35802A7D-CD77-4B0A-BCE8-F10F784EE03A/L0/040, title:"Selfies", subtitle:"(null)" assetCollectionType=2/210
<PHAssetCollection: 0x10574dce0> DD650AAF-3E39-46AE-952F-484857514CD4/L0/040, title:"Live Photos", subtitle:"(null)" assetCollectionType=2/213
<PHAssetCollection: 0x10574de00> 5CFEE773-4485-4B7C-A9AF-9DF0FDAB90F4/L0/040, title:"Hidden", subtitle:"(null)" assetCollectionType=2/205
<PHAssetCollection: 0x10574df20> 3B453048-7296-4010-9E3A-0F812FC2B1FA/L0/040, title:"Panoramas", subtitle:"(null)" assetCollectionType=2/201
<PHAssetCollection: 0x10574e040> 7F229A8E-96DB-4ABD-97FD-70745E4E52D6/L0/040, title:"All Photos", subtitle:"(null)" assetCollectionType=2/209
<PHAssetCollection: 0x10574e160> 5A43BE12-37E6-4617-920E-8600C21D4B03/L0/040, title:"Bursts", subtitle:"(null)" assetCollectionType=2/207   

My question is: where Camera Roll (All Photos) album located now? how can I get it?


Solution

  • Yes, it seems Apple removed Camera Roll album in iOS 13: https://appletoolbox.com/heres-everything-new-in-photos-and-camera-in-ios-13/

    The Camera Roll (All Photos) placement has changed in iOS 13. It has been removed from the Albums tab

    Your 209 magic number means PHAssetCollectionSubtypeSmartAlbumUserLibrary. You can use PHAssetCollectionSubtypeSmartAlbumRecentlyAdded subtype to get "Recents" album, and select "Recents" by default.