5

I have code for fetching the photos from the library and accessing the types. But i have no idea how to check whether the image is PNG or JPEG.? by ALAssetLibrary we can do this easily. I want to implement this by Photos framework. Anyone have any idea.? Any suggestions. Thanks in advance.

Alvin Varghese
  • 842
  • 10
  • 33

2 Answers2

6

Try:

let asset: PHAsset = ...
let opts = PHImageRequestOptions()
// opts.synchronous = true // If you want synchronous callback
opts.version = PHImageRequestOptionsVersion.Original
PHImageManager.defaultManager().requestImageDataForAsset(asset, options: opts) { _, uti, _, _ in
    println(uti)
}

I don't know how to do this without fetching actual data.


To convert UTI to MIME-Type:

import MobileCoreServices

let uti = ...
let mime = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType).takeRetainedValue()
rintaro
  • 51,423
  • 14
  • 131
  • 139
0

Please refer this stack answer using which you can get type of you asset.

https://stackoverflow.com/a/22352132/2098690

Community
  • 1
  • 1
Esha
  • 1,328
  • 13
  • 34