How to get image from iphone device by PHImageFileURLKey
<blockquote>
  <p>I have to send all iPhone gallery images to server. now i am getting all images by this function and saved this image path in core data .`     </p>
</blockquote>

<pre><code>    func getAllImage() {

    let manager = PHImageManager.defaultManager()
    self.assetsFetchResult.enumerateObjectsUsingBlock{(object: AnyObject!,
        count: Int,
        stop: UnsafeMutablePointer&lt;ObjCBool&gt;) 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) -&gt; 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 _ {
    }
}
</code></pre>

<p>And i am fetching all record from core data by this function.</p>

<pre><code>    func fetchDataFromDB() {

    let moc = managedObjectContext
    let photoFetch = NSFetchRequest(entityName: "PhotoLibrary")

    do {
        let searchTerms = CommonUtil.getDataForKey("token")
        photoFetch.predicate = NSPredicate(format: "NOT (accesstoken CONTAINS %@)",searchTerms)
        let photoArray = try moc.executeFetchRequest(photoFetch)

        for result in photoArray
        {
            let match  = result as! NSManagedObject
            let keys = Array(match.entity.attributesByName.keys)
            let dict = match.dictionaryWithValuesForKeys(keys)
            debugPrint(dict)
            let filePath : String  = String(format:  dict["photopath"]! as AnyObject as! String)
            self.arrGallery.addObject(filePath)
        }

    } catch {
        fatalError("Failed to fetch employees: \(error)")
    }
}
</code></pre>

<p>But my problem is that when i convert this image path into  image
and send this image to server it working fine in simulator but i am not able to convert this imagepath into image in device its crashed . I am not able to convert it into image in iPhone device. Please give me any suggestion.</p>