我正在构建一个在B64中返回字符串图像的框架
这是我的行代码
我正在使用UIImageJPEGRepresentation
缩小图像然后将其设为B64
imageb64Min = UIImageJPEGRepresentation(image!, 0)!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
但是每次我在我的应用程序流程中使用这一行时,内存永远不会消失 到达应用程序的限制内存并中断应用程序
任何想法为什么会这样?
编辑:这是我的代码流
func arregloImagenesConDNI(arrImagenes: NSArray, tipoDocumento: TipoDocumento, codigoDNI: BAZQRScan.eCodigo, dni: String)
{
NSLog("Arreglo de Imagenes: %@", arrImagenes.description)
// let ecodigo = codigoDNI as! Int
var fileNames: Array = Array <String>();
var imagesMin: Array = Array <String>();
//for var index = 0; index < arrImagenes.count; index += 1
var imageb64:String?
var imageb64Min:String?
for index in 0 ..< arrImagenes.count {
let image:UIImage? = (arrImagenes[index] as? UIImage)
imageb64 = ABANKUtil.encodeToBase64String(image)
// [UIImageJPEGRepresentation(image, 0.6) base64EncodedStringWithOptions:0];
// let imageb64:String = UIImageJPEGRepresentation(image!, 0)!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
let identifier:String = NSProcessInfo.processInfo().globallyUniqueString
let keys: Array = Array(arrayLiteral: "name", "resource")
let dataToSave:NSDictionary = NSDictionary(objects: [identifier, imageb64!], forKeys: keys);
// [UIImageJPEGRepresentation(image, 0.6) base64EncodedStringWithOptions:0];
imageb64Min = UIImageJPEGRepresentation(image!, 0)!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
// Not really temp files
let sessionPath:String = String(format: "%@%@", ABANKUtil.getDocsPath(), identifier)
NSLog("Create file at path: %@", sessionPath);
dataToSave.writeToFile(sessionPath, atomically: true)
fileNames.append(identifier)
imagesMin.append(imageb64Min!)
}
let jsonNames:NSMutableString = "["
let jsonImages:NSMutableString = "[";
// for var index = 0; index < arrImagenes.count; index += 1
for index in 0 ..< arrImagenes.count {
if index == 0{
jsonNames.appendFormat("\"%@\"", fileNames[index])
jsonImages.appendFormat("\"%@\"", imagesMin[index])
}
else {
jsonNames.appendFormat(",\"%@\"", fileNames[index])
jsonImages.appendFormat(",\"%@\"", imagesMin[index])
}
}
jsonNames.appendString("]")
jsonImages.appendString("]")
print("JsonImages: \(jsonImages)")
print("JsonNames: \(jsonNames)")
let respuesta : String = "{\"codigo\": 0, \"mensaje\": \"Se capturaron las fotos\",\"arrArchBase64\": \(jsonImages) ,\"arrNomArchBase64\": \(jsonNames) ,\"DNI\": \"\(dni)\" ,\"codigoDNI\": \"\(codigoDNI)\"}"
dispatch_async(dispatch_get_main_queue()) {
print("Send response digi")
self.webview?.send(respuesta, callback: self.callback!, scope: self.module!)
}
imageb64 = nil
imageb64Min = nil
self.dismissViewControllerAnimated(true, completion: nil)
}