Last active
April 24, 2019 17:07
-
-
Save tilltue/7248923dd3d8fd4a859007e7ea0a82ef to your computer and use it in GitHub Desktop.
Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomPhotoPickerViewController: TLPhotosPickerViewController { | |
open func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { | |
if let image = (info[.originalImage] as? UIImage) { | |
var placeholderAsset: PHObjectPlaceholder? = nil | |
// Here!! ๐๐๐๐๐ | |
PHPhotoLibrary.shared().performChanges({ | |
let newAssetRequest = PHAssetChangeRequest.creationRequestForAsset(from: image) | |
placeholderAsset = newAssetRequest.placeholderForCreatedAsset | |
}, completionHandler: { [weak self] (sucess, error) in | |
if sucess, let `self` = self, let identifier = placeholderAsset?.localIdentifier { | |
guard let asset = PHAsset.fetchAssets(withLocalIdentifiers: [identifier], options: nil).firstObject else { return } | |
var result = TLPHAsset(asset: asset) | |
result.selectedOrder = self.selectedAssets.count + 1 | |
result.isSelectedFromCamera = true | |
self.selectedAssets.append(result) | |
self.logDelegate?.selectedPhoto(picker: self, at: 1) | |
} | |
}) | |
} | |
else if (info[.mediaType] as? String) == kUTTypeMovie as String { | |
var placeholderAsset: PHObjectPlaceholder? = nil | |
PHPhotoLibrary.shared().performChanges({ | |
let newAssetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: info[.mediaURL] as! URL) | |
placeholderAsset = newAssetRequest?.placeholderForCreatedAsset | |
}) { [weak self] (sucess, error) in | |
if sucess, let `self` = self, let identifier = placeholderAsset?.localIdentifier { | |
guard let asset = PHAsset.fetchAssets(withLocalIdentifiers: [identifier], options: nil).firstObject else { return } | |
var result = TLPHAsset(asset: asset) | |
result.selectedOrder = self.selectedAssets.count + 1 | |
result.isSelectedFromCamera = true | |
self.selectedAssets.append(result) | |
self.logDelegate?.selectedPhoto(picker: self, at: 1) | |
} | |
} | |
} | |
picker.dismiss(animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment