1

In my app I only show assets the user can edit, so I only show photos - no videos. New in iOS 11 Live Photos have two effects that effectively turn the photo into a video - Loop and Bounce. These Live Photos cannot be edited in the Photos app - the plugins button is disabled. I need to filter those out in my PHFetchResult. But mediaType of image still includes these 'live videos'. How can I exclude those from the fetch? Maybe something to do with the playbackStyle of PHAsset?

let photoLibraryFetchResult = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: nil)  
let assetCollection = photoLibraryFetchResult.firstObject!  

let imagesOnlyFetchOptions = PHFetchOptions()  
imagesOnlyFetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue)  

let assetsFetchResults = PHAsset.fetchAssets(in: assetCollection, options: imagesOnlyFetchOptions)
CodeBender
  • 35,668
  • 12
  • 125
  • 132
Jordan H
  • 52,571
  • 37
  • 201
  • 351

1 Answers1

2

Try looking at the playbackStyle value. (Read more here)

The enum has the following options:

case image
case imageAnimated
case livePhoto
case unsupported
case video
case videoLooping
Jordan H
  • 52,571
  • 37
  • 201
  • 351
CodeBender
  • 35,668
  • 12
  • 125
  • 132
  • Cool, the syntax for this is: `NSPredicate(format: "playbackStyle = %d or playbackStyle = %d", PHAsset.PlaybackStyle.image.rawValue, PHAsset.PlaybackStyle.livePhoto.rawValue)` – Jordan H Jun 24 '17 at 22:08