From 7029891b0695f798deb604a550df60aaadf9fede Mon Sep 17 00:00:00 2001 From: geegaset Date: Fri, 2 Sep 2016 14:16:45 +0100 Subject: [PATCH] use camera roll as default pictures source (#215) * use camera roll as default pictures source * creationDate restored --- .../Input/Photos/PhotosInputDataProvider.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ChattoAdditions/Source/Input/Photos/PhotosInputDataProvider.swift b/ChattoAdditions/Source/Input/Photos/PhotosInputDataProvider.swift index 0a418d0..6e99eb3 100644 --- a/ChattoAdditions/Source/Input/Photos/PhotosInputDataProvider.swift +++ b/ChattoAdditions/Source/Input/Photos/PhotosInputDataProvider.swift @@ -66,9 +66,19 @@ class PhotosInputDataProvider: NSObject, PhotosInputDataProviderProtocol, PHPhot private var imageManager = PHCachingImageManager() private var fetchResult: PHFetchResult! override init() { - let options = PHFetchOptions() - options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: false) ] - self.fetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: options) + func fetchOptions(predicate: NSPredicate?) -> PHFetchOptions { + let options = PHFetchOptions() + options.sortDescriptors = [ NSSortDescriptor(key: "creationDate", ascending: false) ] + options.predicate = predicate + return options + } + + if let userLibraryCollection = PHAssetCollection.fetchAssetCollectionsWithType(.SmartAlbum, subtype: .SmartAlbumUserLibrary, options: nil).firstObject as? PHAssetCollection { + self.fetchResult = PHAsset.fetchAssetsInAssetCollection(userLibraryCollection, options: fetchOptions(NSPredicate(format: "mediaType = \(PHAssetMediaType.Image.rawValue)"))) + } + else { + self.fetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions(nil)) + } super.init() PHPhotoLibrary.sharedPhotoLibrary().registerChangeObserver(self) }