phasset

Fetch only photos of type PHAssetMediaTypeImage form asset collection type PHAssetCollectionTypeSmartAlbum

帅比萌擦擦* 提交于 2019-12-09 08:05:24
问题 I am using the Photos framework to fetch album list in iOS8. I am able to do it using PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; This gives me a list of all smart albums including videos. How can I filter out videos from this list. I need only images. Help would be appreciated. Thanks. 回答1: You should set up fetch options, its has a property predicate , which can be

Getting the location of a PHAsset in Swift

左心房为你撑大大i 提交于 2019-12-08 22:02:52
问题 For some reason the location property on a PHAsset is only exposed in Objective-c and not in Swift. Documentation: PHAsset.location To work around it, I figured I could create a Objective-C class whose sole purpose is to extract the location and import it into Swift. LocationGetter.h @interface LocationGetter : NSObject + (CLLocation *)locationForAsset:(PHAsset *) asset; @end LocationGetter.m @implementation LocationGetter + (CLLocation *)locationForAsset:(PHAsset *) asset { return [asset

IOS Photos framework

▼魔方 西西 提交于 2019-12-08 15:58:10
问题 I want to retrieve all the photos from all the local albums on the device. Basically all the photos that are on the device Will the list of local identifiers be unique ? What is the best approach for this using the photos framework. My question is not duplicate since the other question talks about also cloud assets and assets that are not on the device. When retrieving actual data of the image it returns null data when trying to fetch synchronize. 回答1: I want to retrieve all the photos from

Accessing iCloud photos uniquely on multiple devices using PHAsset

二次信任 提交于 2019-12-07 11:14:47
问题 Is there a way of accessing a specific PHAsset in an iCloud album uniquely on multiple devices? I have written a simple app that lists thumbnails and .localIdentifier s from an iCloud shared album, and (naturally) it shows the same images on different devices, however, the localIdentifiers are different for the same images on different devices (not so unexpected as it is a "local" identifier). However, what I actually want to do is associate a record in a cloud-shared CoreData database with

Get an edited photo's URL from PHAsset

元气小坏坏 提交于 2019-12-06 08:20:06
问题 I'm trying to get a photo's URL from a PHAsset using this code. let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions() options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData) -> Bool in return true } asset.requestContentEditingInput(with: options, completionHandler: { (contentEditingInput, info) in guard let url = contentEditingInput?.fullSizeImageURL else { observer.onError(PHAssetError.imageRequestFailed) return } /// Using this `url` }) Most of

How to get all PHAssets from MacOS's Photo Library

浪尽此生 提交于 2019-12-06 03:10:53
I want to parse all images from my MacOS Photos Library, using PHAsset . However all examples I find are only working for iOS, like the one below, where the last line, which retrieves the assets is not available on macos framework: NSMutableArray *photos = [[NSMutableArray alloc] init]; PHFetchOptions *allPhotosOptions = [[PHFetchOptions alloc] init]; allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]]; // Below compilation error as fetchAssetsWithMediaType is only on iOS framework PHFetchResult *allPhotos = [PHAsset

While converting PHAsset to UIImage losing transparency

南笙酒味 提交于 2019-12-06 00:52:31
After I pick an image from Image picker and try to convert PHAsset to UIImage image is losing transparency of the png Image. I tried searching everywhere but didn't find anything about it. func getAssetThumbnail(asset: PHAsset) -> UIImage { let manager = PHImageManager.defaultManager() let option = PHImageRequestOptions() var thumbnail = UIImage() option.synchronous = true manager.requestImageForAsset(asset, targetSize: CGSize(width: 341.0, height: 182.0), contentMode: .AspectFit, options: option, resultHandler: {(result, info)->Void in thumbnail = result! }) return thumbnail } Image before

How to compare PHAsset to UIImage

余生长醉 提交于 2019-12-06 00:37:37
I have converted some PHAsset to UIImage : PHImageManager *manager = [PHImageManager defaultManager]; [manager requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:requestOptions resultHandler:^void(UIImage *image, NSDictionary *info) { convertedImage = image; [images addObject:convertedImage]; }]; Now I want to do something like that: [selectedAssets removeObject:image]; where selectedAssets is an array of PHAsset and image is an UIImage so I have implemented the isEqual like that: - (BOOL)isEqual:(id)other { if (other == self) return

Saving photo with metadata into Camera Roll with specific file name

百般思念 提交于 2019-12-05 10:55:13
I'm trying to save an image with exif metadata using following code: +(void)saveImageWithMetaToCameraRoll:(UIImage*)image location:(CLLocation*)location album:(PHAssetCollection *)album exif:(NSDictionary *)metadata isOriginal:(BOOL)isOriginal isFavorite:(BOOL)isFavorite completionBlock:(PHAssetBoolBlock)completionBlock { NSMutableDictionary *meta = [metadata mutableCopy]; NSData *imageData = UIImageJPEGRepresentation(image, 1.0f); CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) imageData, NULL); if (!isOriginal) { [meta resetOrientation]; } NSString *timestamp =

PHAsset (or ALAsset) cross-device identifier

巧了我就是萌 提交于 2019-12-05 09:54:00
I am actually creating an iOS app, and want to store some details about Photo Library pictures in an SQLite database. I also would like to be able to share this data across the different devices the user has (imagine someone wanted to reorganize pictures on his iPhone, and wants to retrieve the same order in his iPad). I have searched across the Apple documentation, but did not find any PHAsset identifier that is shared across devices. I also tried to check if the PHImageFileURLKey , hashValue , or localIdentifier of the PHAsset where shared, but none of them are. Has someone already done