Skip to content

Commit

Permalink
support iCloud photo library.
Browse files Browse the repository at this point in the history
mute live photos playback.
  • Loading branch information
tilltue committed Nov 13, 2017
1 parent bd86e59 commit b7e3298
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 28 deletions.
14 changes: 13 additions & 1 deletion Example/TLPhotoPicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0910;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
Expand Down Expand Up @@ -474,14 +474,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -521,14 +527,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0910"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -40,6 +40,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -69,6 +70,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
43 changes: 35 additions & 8 deletions Example/TLPhotoPicker/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="TLPhotoPicker_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="3bJ-bG-tue">
<rect key="frame" x="72.5" y="229.5" width="229" height="208"/>
<rect key="frame" x="73" y="230" width="229" height="208"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zpy-9h-CPz">
<rect key="frame" x="0.0" y="0.0" width="229" height="36"/>
Expand Down Expand Up @@ -52,13 +49,43 @@
</button>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="u8O-io-kHd">
<rect key="frame" x="137.5" y="448" width="100" height="112"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="get image message" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9CM-MS-96X">
<rect key="frame" x="3" y="0.0" width="94" height="12"/>
<fontDescription key="fontDescription" type="system" pointSize="10"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="cmZ-5x-q5A">
<rect key="frame" x="0.0" y="12" width="100" height="100"/>
<constraints>
<constraint firstAttribute="width" priority="999" constant="100" id="JKR-LF-zar"/>
<constraint firstAttribute="height" priority="999" constant="100" id="nEq-0R-eJw"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstItem="cmZ-5x-q5A" firstAttribute="leading" secondItem="u8O-io-kHd" secondAttribute="leading" id="2Ql-R8-x1R"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="3bJ-bG-tue" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="CcD-Da-gQv"/>
<constraint firstItem="u8O-io-kHd" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="lA3-4a-42x" secondAttribute="leading" constant="10" id="8HN-Pp-bEG"/>
<constraint firstItem="3bJ-bG-tue" firstAttribute="centerX" secondItem="lA3-4a-42x" secondAttribute="centerX" id="CcD-Da-gQv"/>
<constraint firstItem="3bJ-bG-tue" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="F30-UI-4xu"/>
<constraint firstItem="u8O-io-kHd" firstAttribute="centerX" secondItem="lA3-4a-42x" secondAttribute="centerX" id="QNi-AT-wIC"/>
<constraint firstItem="u8O-io-kHd" firstAttribute="top" secondItem="3bJ-bG-tue" secondAttribute="bottom" constant="10" id="g2B-Ox-fJs"/>
<constraint firstItem="lA3-4a-42x" firstAttribute="trailing" relation="greaterThanOrEqual" secondItem="u8O-io-kHd" secondAttribute="trailing" constant="10" id="tzs-vU-PM0"/>
</constraints>
<viewLayoutGuide key="safeArea" id="lA3-4a-42x"/>
</view>
<connections>
<outlet property="imageView" destination="cmZ-5x-q5A" id="ow7-S0-GhT"/>
<outlet property="label" destination="9CM-MS-96X" id="QQI-9N-Ft8"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
Expand Down
2 changes: 1 addition & 1 deletion Example/TLPhotoPicker/TLPhotosPicker+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import TLPhotoPicker

extension TLPhotosPickerViewController {
class func custom(withTLPHAssets: (([TLPHAsset]) -> Void)? = nil, didCancel: ((Void) -> Void)? = nil) -> CustomPhotoPickerViewController {
class func custom(withTLPHAssets: (([TLPHAsset]) -> Void)? = nil, didCancel: (() -> Void)? = nil) -> CustomPhotoPickerViewController {
let picker = CustomPhotoPickerViewController(withTLPHAssets: withTLPHAssets, didCancel:didCancel)
return picker
}
Expand Down
31 changes: 30 additions & 1 deletion Example/TLPhotoPicker/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import Photos
class ViewController: UIViewController,TLPhotosPickerViewControllerDelegate {

var selectedAssets = [TLPHAsset]()

@IBOutlet var label: UILabel!
@IBOutlet var imageView: UIImageView!

@IBAction func pickerButtonTap() {
let viewController = CustomPhotoPickerViewController()
viewController.delegate = self
Expand Down Expand Up @@ -63,6 +65,33 @@ class ViewController: UIViewController,TLPhotosPickerViewControllerDelegate {
func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
// use selected order, fullresolution image
self.selectedAssets = withTLPHAssets
getFirstSelectedImage()
}

func getFirstSelectedImage() {
if let asset = self.selectedAssets.first {
if let image = asset.fullResolutionImage {
print(image)
self.label.text = "local storage image"
self.imageView.image = image
}else {
print("Can't get image at local storage, try download image")
asset.cloudImageDownload(progressBlock: { [weak self] (progress) in
DispatchQueue.main.async {
self?.label.text = "download \(100*progress)%"
print(progress)
}
}, completionBlock: { [weak self] (image) in
if let image = image {
//use image
DispatchQueue.main.async {
self?.label.text = "complete download"
self?.imageView.image = image
}
}
})
}
}
}

func dismissPhotoPicker(withPHAssets: [PHAsset]) {
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ TLPhotoPicker enables application to pick images and videos from multiple smart
- async phasset request and displayed cell.
- scrolling performance is better than facebook in displaying video assets collection.
- custom cell
- reload of changes that occur in the Photos library.
- reload of changes that occur in the Photos library.
- support iCloud Photo Library

| Smart album collection | LivePhotoCell | VideoPhotoCell | PhotoCell | CustomCell(instagram) |
| ------------- | ------------- | ------------- | ------------- | ------------- |
Expand Down Expand Up @@ -137,6 +138,9 @@ public struct TLPHAsset {
public var type: AssetType
// get full resolution image
public var fullResolutionImage: UIImage?
// get async icloud image (download)
@discardableResult
public func cloudImageDownload(progressBlock: @escaping (Double) -> Void, completionBlock:@escaping (UIImage?)-> Void ) -> PHImageRequestID?
// get original asset file name
public var originalFileName: String?
}
Expand All @@ -159,7 +163,7 @@ public struct TLPhotosPickerConfigure {
public var allowedVideoRecording = true
public var maxVideoDuration:TimeInterval? = nil
public var autoPlay = true
public var muteAudio = false
public var muteAudio = true
public var mediaType: PHAssetMediaType? = nil
public var numberOfColumn = 3
public var maxSelectedAssets: Int? = nil //default: inf
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.4'
s.version = '1.3.5'
s.summary = 'multiple phassets picker for iOS lib. like facebook'

# This description is used to generate tags and improve search results.
Expand Down
5 changes: 5 additions & 0 deletions TLPhotoPicker/Classes/TLAssetsCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public struct TLPHAsset {
return TLPhotoLibrary.fullResolutionImageData(asset: phAsset)
}
}
@discardableResult
public func cloudImageDownload(progressBlock: @escaping (Double) -> Void, completionBlock:@escaping (UIImage?)-> Void ) -> PHImageRequestID? {
guard let phAsset = self.phAsset else { return nil }
return TLPhotoLibrary.cloudImageDownload(asset: phAsset, progressBlock: progressBlock, completionBlock: completionBlock)
}
public var originalFileName: String? {
get {
guard let phAsset = self.phAsset,let resource = PHAssetResource.assetResources(for: phAsset).first else { return nil }
Expand Down
9 changes: 5 additions & 4 deletions TLPhotoPicker/Classes/TLPhotoLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ class TLPhotoLibrary {
}

@discardableResult
func imageAsset(asset: PHAsset, size: CGSize = CGSize(width: 720, height: 1280), options: PHImageRequestOptions? = nil, completionBlock:@escaping (UIImage)-> Void ) -> PHImageRequestID {
func imageAsset(asset: PHAsset, size: CGSize = CGSize(width: 160, height: 160), options: PHImageRequestOptions? = nil, completionBlock:@escaping (UIImage)-> Void ) -> PHImageRequestID {
var options = options
if options == nil {
options = PHImageRequestOptions()
options?.isSynchronous = false
options?.deliveryMode = .highQualityFormat
options?.isNetworkAccessAllowed = false
options?.isNetworkAccessAllowed = true
}
let requestId = self.imageManager.requestImage(for: asset, targetSize: size, contentMode: .aspectFill, options: options) { image, info in
if let image = image {
Expand All @@ -74,7 +75,7 @@ class TLPhotoLibrary {
}

@discardableResult
func cloudImageDownload(asset: PHAsset, size: CGSize = PHImageManagerMaximumSize, progressBlock: @escaping (Double) -> Void, completionBlock:@escaping (UIImage?)-> Void ) -> PHImageRequestID {
class func cloudImageDownload(asset: PHAsset, size: CGSize = PHImageManagerMaximumSize, progressBlock: @escaping (Double) -> Void, completionBlock:@escaping (UIImage?)-> Void ) -> PHImageRequestID {
let options = PHImageRequestOptions()
options.isSynchronous = false
options.isNetworkAccessAllowed = true
Expand All @@ -84,7 +85,7 @@ class TLPhotoLibrary {
options.progressHandler = { (progress,error,stop,info) in
progressBlock(progress)
}
let requestId = self.imageManager.requestImageData(for: asset, options: options) { (imageData, dataUTI, orientation, info) in
let requestId = PHCachingImageManager().requestImageData(for: asset, options: options) { (imageData, dataUTI, orientation, info) in
if let data = imageData,let _ = info {
completionBlock(UIImage(data: data))
}
Expand Down
Loading

0 comments on commit b7e3298

Please sign in to comment.