PHAsset+Utility.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // PHAsset+Utilities.h
  3. //
  4. // Created by Zakk Hoyt on 9/22/14.
  5. // Copyright (c) 2014 Zakk Hoyt. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. @import Photos;
  9. typedef void (^PHAssetBoolBlock)(BOOL success);
  10. typedef void (^PHAssetMetadataBlock)(NSDictionary *metadata);
  11. typedef void (^PHAssetAssetBoolBlock)(PHAsset *asset, BOOL success);
  12. @interface PHAsset (Utilities)
  13. /*!
  14. @method saveToAlbum:completionBlock
  15. @description Save a copy of a PHAsset to a photo album. Will create the album if it doesn't exist.
  16. @param title The title of the album.
  17. @param completionBlock This block is passed a BOOL for success. This parameter may be nil.
  18. */
  19. -(void)saveToAlbum:(NSString*)title completionBlock:(PHAssetBoolBlock)completionBlock;
  20. /*!
  21. @method requestMetadataWithCompletionBlock
  22. @description Get metadata dictionary of an asset (the kind with {Exif}, {GPS}, etc...
  23. @param completionBlock This block is passed a dictionary of metadata properties. See ImageIO framework for parsing/reading these. This parameter may be nil.
  24. */
  25. -(void)requestMetadataWithCompletionBlock:(PHAssetMetadataBlock)completionBlock;
  26. /*!
  27. @method updateLocation:creationDate:completionBlock
  28. @description Update the location and date of an existing asset
  29. @param location A CLLocation object to be written to the PHAsset. See CoreLocation framework for obtaining locations.
  30. @param creationDate An NSDate to be written to the PHAsset.
  31. @param completionBlock This block is passed the PHAsset updated with location/date (if applied) and BOOL for success. This parameter may be nil.
  32. */
  33. -(void)updateLocation:(CLLocation*)location creationDate:(NSDate*)creationDate completionBlock:(PHAssetBoolBlock)completionBlock;
  34. /*!
  35. @method saveImageToCameraRoll:location:completionBlock
  36. @description Save an image to camera roll with optional completion (returns PHAsset in completion block)
  37. @param location A CLLocation object to be written to the PHAsset. See CoreLocation framework for obtaining locations. This parameter may be nil.
  38. @param creationDate An NSDate to be written to the PHAsset.
  39. @param completionBlock Returns the PHAsset which was written and BOOL for success. This parameter may be nil.
  40. */
  41. +(void)saveImageToCameraRoll:(UIImage*)image location:(CLLocation*)location completionBlock:(PHAssetAssetBoolBlock)completionBlock;
  42. /*!
  43. @method saveVideoAtURL:location:completionBlock
  44. @description Save a video to camera roll with optional completion (returns PHAsset in completion block)
  45. @param location A CLLocation object to be written to the PHAsset. See CoreLocation framework for obtaining locations. This parameter may be nil.
  46. @param creationDate An NSDate to be written to the PHAsset.
  47. @param completionBlock Returns the PHAsset which was written and BOOL for success. This parameter may be nil.
  48. */
  49. +(void)saveVideoAtURL:(NSURL*)url location:(CLLocation*)location completionBlock:(PHAssetAssetBoolBlock)completionBlock;
  50. @end