How to fetch all images from custom Photo Album – Swift

For Swift 4 using this answer https://stackoverflow.com/a/28904792/4795651 edited a little for myself. import Photos func fetchCustomAlbumPhotos() { let albumName = “Album Name Here” var assetCollection = PHAssetCollection() var albumFound = Bool() var photoAssets = PHFetchResult<AnyObject>() let fetchOptions = PHFetchOptions() fetchOptions.predicate = NSPredicate(format: “title = %@”, albumName) let collection:PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions) … Read more

How to get URL for a PHAsset? [duplicate]

I used @iMHitesh Surani answer and it worked perfect, I converted it into Swift 3.1 and put it into an extension of PHAsset in order to use that method everywhere, here it is: extension PHAsset { func getURL(completionHandler : @escaping ((_ responseURL : URL?) -> Void)){ if self.mediaType == .image { let options: PHContentEditingInputRequestOptions = … Read more

How to get an ALAsset URL from a PHAsset?

Create the assetURL by leveraging the localidentifier of the PHAsset. Example: PHAsset.localidentifier returns 91B1C271-C617-49CE-A074-E391BA7F843F/L0/001 Now take the 32 first characters to build the assetURL, like: assets-library://asset/asset.JPG?id=91B1C271-C617-49CE-A074-E391BA7F843F&ext=JPG You might change the extension JPG depending on the UTI of the asset (requestImageDataForAsset returns the UTI), but in my testing the extensions of the assetURL seems to be … Read more

Save images with phimagemanager to custom album?

This is how I do: At the top: import Photos var image: UIImage! var assetCollection: PHAssetCollection! var albumFound : Bool = false var photosAsset: PHFetchResult! var assetThumbnailSize:CGSize! var collection: PHAssetCollection! var assetCollectionPlaceholder: PHObjectPlaceholder! Creating the album: func createAlbum() { //Get PHFetch Options let fetchOptions = PHFetchOptions() fetchOptions.predicate = NSPredicate(format: “title = %@”, “camcam”) let collection … Read more