Skip to content

Commit

Permalink
support get all album
Browse files Browse the repository at this point in the history
  • Loading branch information
tilltue committed Dec 23, 2017
1 parent a505f66 commit 012f3c6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
9 changes: 8 additions & 1 deletion Example/TLPhotoPicker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ViewController: UIViewController,TLPhotosPickerViewControllerDelegate {
}
var configure = TLPhotosPickerConfigure()
configure.numberOfColumn = 3
configure.getAllAlbum = true
//configure.maxSelectedAssets = 10
//configure.nibSet = (nibName: "CustomCell_Instagram", bundle: Bundle.main)
viewController.configure = configure
Expand Down Expand Up @@ -74,7 +75,13 @@ class ViewController: UIViewController,TLPhotosPickerViewControllerDelegate {
asset.tempCopyMediaFile(progressBlock: { (progress) in
print(progress)
}, completionBlock: { (url, mimeType) in
print(url)
func fileSize(_ url: URL?) -> Int? {
do {
guard let fileSize = try url?.resourceValues(forKeys: [.fileSizeKey]).fileSize else { return nil }
return fileSize
}catch { return nil }
}
print(fileSize(url))
print(mimeType)
})
}
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.4.1'
s.version = '1.4.2'
s.summary = 'multiple phassets picker for iOS lib. like facebook'

# This description is used to generate tags and improve search results.
Expand Down
33 changes: 29 additions & 4 deletions TLPhotoPicker/Classes/TLPhotoLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TLPhotoLibrary {
}()

deinit {
//print("deinit TLPhotoLibrary")
// print("deinit TLPhotoLibrary")
}

@discardableResult
Expand Down Expand Up @@ -132,9 +132,31 @@ extension TLPhotoLibrary {
return PHAsset.fetchAssets(in: phAssetCollection, options: options)
}

func fetchCollection(allowedVideo: Bool = true, useCameraButton: Bool = true, mediaType: PHAssetMediaType? = nil, maxVideoDuration:TimeInterval? = nil,options: PHFetchOptions? = nil) {

let options = options ?? getOption()
func fetchCollection(configure: TLPhotosPickerConfigure) {
let allowedVideo = configure.allowedVideo
let useCameraButton = configure.usedCameraButton
let mediaType = configure.mediaType
let maxVideoDuration = configure.maxVideoDuration
let getAllAlbum = configure.getAllAlbum
let options = configure.fetchOption ?? getOption()

@discardableResult
func getAlbum(subType: PHAssetCollectionSubtype, result: inout [TLAssetsCollection]) {
let fetchCollection = PHAssetCollection.fetchAssetCollections(with: .album, subtype: subType, options: nil)
var collections = [PHAssetCollection]()
fetchCollection.enumerateObjects { (collection, index, _) in
collections.append(collection)
}
for collection in collections {
if !result.contains(where: { $0.localIdentifier == collection.localIdentifier }) {
var assetsCollection = TLAssetsCollection(collection: collection)
assetsCollection.fetchResult = PHAsset.fetchAssets(in: collection, options: options)
if assetsCollection.count > 0 {
result.append(assetsCollection)
}
}
}
}

@discardableResult
func getSmartAlbum(subType: PHAssetCollectionSubtype, result: inout [TLAssetsCollection]) -> TLAssetsCollection? {
Expand Down Expand Up @@ -176,6 +198,9 @@ extension TLPhotoLibrary {
getSmartAlbum(subType: .smartAlbumPanoramas, result: &assetCollections)
//Favorites
getSmartAlbum(subType: .smartAlbumFavorites, result: &assetCollections)
if getAllAlbum {
getAlbum(subType: .any, result: &assetCollections)
}
if allowedVideo {
//Videos
getSmartAlbum(subType: .smartAlbumVideos, result: &assetCollections)
Expand Down
3 changes: 2 additions & 1 deletion TLPhotoPicker/Classes/TLPhotosPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public struct TLPhotosPickerConfigure {
public var allowedLivePhotos = true
public var allowedVideo = true
public var allowedVideoRecording = true
public var getAllAlbum = false
public var maxVideoDuration:TimeInterval? = nil
public var autoPlay = true
public var muteAudio = false
Expand Down Expand Up @@ -278,7 +279,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, options: self.configure.fetchOption)
self.photoLibrary.fetchCollection(configure: self.configure)
}else{
//self.dismiss(animated: true, completion: nil)
}
Expand Down

0 comments on commit 012f3c6

Please sign in to comment.