Skip to content

Commit

Permalink
add fetct option
Browse files Browse the repository at this point in the history
  • Loading branch information
tilltue committed Dec 12, 2017
1 parent 739bd0c commit 1593812
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public struct TLPhotosPickerConfigure {
public var mediaType: PHAssetMediaType? = nil
public var numberOfColumn = 3
public var maxSelectedAssets: Int? = nil //default: inf
public var fetchOption: PHFetchOptions? = nil
public var singleSelectedMode = false
public var selectedColor = UIColor(red: 88/255, green: 144/255, blue: 255/255, alpha: 1.0)
public var cameraBgColor = UIColor(red: 221/255, green: 223/255, blue: 226/255, alpha: 1)
Expand Down
2 changes: 1 addition & 1 deletion TLPhotoPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'TLPhotoPicker'
s.version = '1.3.7'
s.version = '1.3.8'
s.summary = 'multiple phassets picker for iOS lib. like facebook'

# This description is used to generate tags and improve search results.
Expand Down
11 changes: 6 additions & 5 deletions TLPhotoPicker/Classes/TLPhotoLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,23 @@ class TLPhotoLibrary {
extension TLPhotoLibrary {
func getOption() -> PHFetchOptions {
let options = PHFetchOptions()
let sortOrder = [NSSortDescriptor(key: "modificationDate", ascending: false)]
let sortOrder = [NSSortDescriptor(key: "creationDate", ascending: false)]
options.sortDescriptors = sortOrder
return options
}

func fetchResult(collection: TLAssetsCollection?, maxVideoDuration:TimeInterval?=nil) -> PHFetchResult<PHAsset>? {
func fetchResult(collection: TLAssetsCollection?, maxVideoDuration:TimeInterval?=nil, options: PHFetchOptions? = nil) -> PHFetchResult<PHAsset>? {
guard let phAssetCollection = collection?.phAssetCollection else { return nil }
let options = getOption()
let options = options ?? getOption()
if let duration = maxVideoDuration, phAssetCollection.assetCollectionSubtype == .smartAlbumVideos {
options.predicate = NSPredicate(format: "mediaType = %i AND duration <= %f", PHAssetMediaType.video.rawValue, duration)
}
return PHAsset.fetchAssets(in: phAssetCollection, options: options)
}

func fetchCollection(allowedVideo: Bool = true, useCameraButton: Bool = true, mediaType: PHAssetMediaType? = nil, maxVideoDuration:TimeInterval? = nil) {
let options = getOption()
func fetchCollection(allowedVideo: Bool = true, useCameraButton: Bool = true, mediaType: PHAssetMediaType? = nil, maxVideoDuration:TimeInterval? = nil,options: PHFetchOptions? = nil) -> PHFetchResult<PHAsset>? {

let options = options ?? getOption()

@discardableResult
func getSmartAlbum(subType: PHAssetCollectionSubtype, result: inout [TLAssetsCollection]) -> TLAssetsCollection? {
Expand Down
5 changes: 3 additions & 2 deletions TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public struct TLPhotosPickerConfigure {
public var numberOfColumn = 3
public var singleSelectedMode = false
public var maxSelectedAssets: Int? = nil
public var fetchOption: PHFetchOptions? = nil
public var selectedColor = UIColor(red: 88/255, green: 144/255, blue: 255/255, alpha: 1.0)
public var cameraBgColor = UIColor(red: 221/255, green: 223/255, blue: 226/255, alpha: 1)
public var cameraIcon = TLBundle.podBundleImage(named: "camera")
Expand Down Expand Up @@ -277,7 +278,7 @@ extension TLPhotosPickerViewController {
fileprivate func initPhotoLibrary() {
if PHPhotoLibrary.authorizationStatus() == .authorized {
self.photoLibrary.delegate = self
self.photoLibrary.fetchCollection(allowedVideo: self.allowedVideo, useCameraButton: self.usedCameraButton, mediaType: self.configure.mediaType, maxVideoDuration:self.configure.maxVideoDuration)
self.photoLibrary.fetchCollection(allowedVideo: self.allowedVideo, useCameraButton: self.usedCameraButton, mediaType: self.configure.mediaType, maxVideoDuration:self.configure.maxVideoDuration, options: self.configure.fetchOption)
}else{
//self.dismiss(animated: true, completion: nil)
}
Expand All @@ -301,7 +302,7 @@ extension TLPhotosPickerViewController {
self.collections[getfocusedIndex()].recentPosition = self.collectionView.contentOffset
var reloadIndexPaths = [IndexPath(row: getfocusedIndex(), section: 0)]
self.focusedCollection = collection
self.focusedCollection?.fetchResult = self.photoLibrary.fetchResult(collection: collection, maxVideoDuration:self.configure.maxVideoDuration)
self.focusedCollection?.fetchResult = self.photoLibrary.fetchResult(collection: collection, maxVideoDuration:self.configure.maxVideoDuration, options: self.configure.fetchOption)
reloadIndexPaths.append(IndexPath(row: getfocusedIndex(), section: 0))
self.albumPopView.tableView.reloadRows(at: reloadIndexPaths, with: .none)
self.albumPopView.show(false, duration: 0.2)
Expand Down

0 comments on commit 1593812

Please sign in to comment.