我使用此功能扫描iPhone / iPad中相机相册中的所有照片。我不知道为什么,对我来说它一直在崩溃。我真的不知道它在这个函数中崩溃的位置,。当我在iPhone / iPad中的设置中将iCloud Photo Stream更改为ON / OFF时,有时它工作正常。我不知道为什么会这样。
这是我写的功能。我正在将PHAssets数组传递给这个函数。
func gettingSize(from array : NSMutableArray)
{
func enumerateAllImages(imageArray : NSMutableArray, completion : ((ArrayPassed : NSMutableArray) -> Void)?)
{
// Performing progressView addition
var TempArray : NSMutableArray = NSMutableArray()
var options : PHImageRequestOptions = PHImageRequestOptions()
options.synchronous = true
options.networkAccessAllowed = false // to skip download image from iCloud
let imageManager : PHImageManager = PHImageManager()
for index in 0...(imageArray.count - 1)
{
var ID = imageManager.requestImageDataForAsset( imageArray[index] as PHAsset, options: options, resultHandler:
{
data,stringValue,orientation,object in
var value : NSString = stringValue
if (value as NSString).containsString(".png")
{
if let isIniCloud = object as NSDictionary?
{
var isIniCloudDICT : NSDictionary = isIniCloud
if let integerCloudValue = isIniCloudDICT.valueForKeyPath(PHImageResultIsInCloudKey) as? Int
{
if integerCloudValue == 0
{
if index == (imageArray.count - 1)
{
self.tempImageSize = self.tempImageSize + data.length
TempArray.addObject(imageArray[index])
self.increasingTheValue()
completion!(ArrayPassed: TempArray)
}
else
{
self.tempImageSize = self.tempImageSize + data.length
TempArray.addObject(imageArray[index])
}
} // Checking condition for integerValueCloud
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}
} // Is in iCloud Optional checking
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}
} // Is in iCloud NSDictionary optional checking
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}
}
else
{
if index == (imageArray.count - 1)
{
completion!(ArrayPassed: TempArray)
}
}
}) // Image Manager
} // For loop
} // Nested Function
enumerateAllImages( array, { ArrayPassed in
if ArrayPassed.count == 0
{
dispatch_async(dispatch_get_main_queue(), {
self.progressView.progress = 0
self.tempProgress = 0
self.increasingTheValue()
})
}
else
{
self.Array = ArrayPassed
}
})
}
有人知道为什么会这样,当我运行它时,它会崩溃吗?这条线上的裂缝
var value : NSString = stringValue
多次,不知道为什么会这样。?