我必须将所有iPhone图库图像发送到服务器。现在我通过此功能获取所有图像,并将此图像路径保存在核心数据中。“
_gameNode.addChild(ballNode!)
我正在通过此功能获取核心数据的所有记录。
func getAllImage() {
let manager = PHImageManager.defaultManager()
self.assetsFetchResult.enumerateObjectsUsingBlock{(object: AnyObject!,
count: Int,
stop: UnsafeMutablePointer<ObjCBool>) in
if object is PHAsset{
let asset = object as! PHAsset
let imageSize = CGSize(width: asset.pixelWidth,
height: asset.pixelHeight)
/* For faster performance, and maybe degraded image */
let options = PHImageRequestOptions()
options.deliveryMode = .FastFormat
options.synchronous = true
manager.requestImageForAsset(asset,
targetSize: imageSize,
contentMode: .AspectFill,
options: options,
resultHandler: {
(image, info) -> Void in
debugPrint(object.localIdentifier)
//object.localIdentifier
if let imageURL : NSURL? = info!["PHImageFileURLKey"] as AnyObject? as? NSURL
{
if imageURL != nil{
// let urlString: String = imageURL!.path!
let urlString: String = (imageURL?.lastPathComponent)!
self.createTask(urlString)
print("this is image path \(info!["PHImageFileURLKey"])")
}
}
}
)
}
}
}
func createTask(imagePath : String) {
let entityDescripition = NSEntityDescription.entityForName("PhotoLibrary", inManagedObjectContext: managedObjectContext)
let task = Tasks(entity: entityDescripition!, insertIntoManagedObjectContext: managedObjectContext)
task.frameid = "1"
task.photopath = imagePath
task.accesstoken = ""
task.photoname = "abc"
task.deliverystatus = "no"
do {
try managedObjectContext.save()
} catch _ {
}
}
但我的问题是,当我将此图像路径转换为图像时 并将此图像发送到服务器,它在模拟器中正常工作,但我无法将此图像路径转换为设备崩溃的图像。我无法将其转换为iPhone设备中的图像。请给我任何建议。