Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@MatthiasHoldorf
Created October 26, 2015 08:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthiasHoldorf/b4d0488641feb5d8ec55 to your computer and use it in GitHub Desktop.
Save MatthiasHoldorf/b4d0488641feb5d8ec55 to your computer and use it in GitHub Desktop.
swift-photos-metadata
import UIKit
import Photos
import AssetsLibrary
class ViewController: UIViewController {
private var images : PHFetchResult!
override func viewDidLoad() {
super.viewDidLoad()
// Retrieve model from all photos
images = PHAsset.fetchAssetsWithMediaType(.Image, options: nil)
// Amount of pictures on the device
print("Amount of pictures on device: " + images.count.description)
// Is the last picture a favoirte?
(images[images.count-1] as! PHAsset).favorite ? print("The last picture is not a favorite!") : print("The last picture is a favorite!")
// Retrieve metadata from the last picture on the device
let asset = images[images.count-1] as! PHAsset
asset.requestContentEditingInputWithOptions(nil) { (contentEditingInput: PHContentEditingInput?, _) -> Void in
//Get full image
let url = contentEditingInput!.fullSizeImageURL
let orientation = contentEditingInput!.fullSizeImageOrientation
var inputImage = CIImage(contentsOfURL: url!)
inputImage = inputImage!.imageByApplyingOrientation(orientation)
for (key, value) in inputImage!.properties {
print("key: \(key)")
print("value: \(value)")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment