lundi 23 mars 2015

Checking MIMe type of images crashing in swift

I used this function to scan all photos from the Camera Album in iPhone/ iPad. I don't know why, for me it was crashing all the time. I really don't have any idea about where it is crashing in this function, i think that finding the MIME type is problem. Sometimes it worked fine, when i changed iCloud Photo Stream to ON/OFF in Settings in iPhone/IPad. I have no idea why this happens.


This is the function which i wrote, I am passing array of PHAssets into this function.



func gettingImages(from array : NSMutableArray)
{

// Performing progressView addition


var options : PHImageRequestOptions = PHImageRequestOptions()
options.synchronous = true
options.networkAccessAllowed = false // to skip download image from iCloud

let imageManager : PHImageManager = PHImageManager()

for index in 0...(array.count - 1)
{

var ID = imageManager.requestImageDataForAsset( array[index] as PHAsset, options: options, resultHandler: {

data,string,orientation,object in

if string == "public.png"
{

if let isIniCloud = object? [PHImageResultIsInCloudKey] as? NSNumber
{

if isIniCloud == 0
{

if let MIME = UTTypeCopyPreferredTagWithClass(string, kUTTagClassMIMEType)?.takeUnretainedValue()
{


if index == (array.count - 1)
{
if MIME == "image/png"
{ self.ImageArray.addObject(array[index])
}
}
else
{
if MIME == "image/png"
{ self.ImageArray.addObject(array[index])
}

}

} // End Of MIME type checking

} // Is in iCloud

} // Is in iCloud
}

}) // Image Manager

} // For loop
}


Is there anybody knows why this happens, when i run it, it crashes.? Sometimes when i switch between iCloud Photo Stream ON/OFF, it works (very rare). Is this because of string value which am passing into UITypeCopy..Class.???




Aucun commentaire:

Enregistrer un commentaire