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.
If you are having trouble and want to check if you photo is a JPEG, look at the writing under the photo in its file name. If it ends . jpg or . jpeg- then the file is a JPEG and will upload.
Open a file in a Hex editor (or just a binary file viewer). PNG files start with 'PNG', . jpg files should have 'exif'or 'JFIF' somewhere in the beginning.
Start by navigating to the location of the document, video, or image, and then perform a Haptic Touch gesture (long-press) on the item. On the menu that pops up, tap Info. You can then see the file format listed next to the file name.
A representation of an image, video, or Live Photo in the Photos library.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With