Created
October 26, 2015 08:45
-
-
Save MatthiasHoldorf/b4d0488641feb5d8ec55 to your computer and use it in GitHub Desktop.
swift-photos-metadata
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
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