Search code examples
iosiphoneswiftphotosphasset

Is it possible to get photos stored on the iPhone without PHAsset?


Is it possible to get the photos stored on the iPhone without use PHAsset ?

It's because the use of PHAsset forces me to use this method :

PHImageManager.defaultManager().requestImageForAsset( ... )

And this method takes times to be executed.

I just want to get the images directly from the folder where they're stored.


Solution

  • It's not possible to access these files directly as they are out of the Sandbox auf your application. What takes time, when you use the method

    PHImageManager.defaultManager().requestImageForAsset( ... )
    

    is that the file gets loaded into memory and decoded into an UIImage. To avoid this please have a look at the method

    PHImageManager.defaultManager(). requestImageDataForAsset( ... )
    

    This method loads the file as NSData.

    Note: If you want to build a Photo application, where users can swipe between photos, the best strategy may be the following.

    1. Preload the images the user is likely to load (e.g. one photo before and after the current displayed one) using PHCachingImageManager
    2. When the user swiped to the actual image use

      PHImageManager.defaultManager().requestImageForAsset( ... )

    As the image are preloaded, this should be much quicker

    Another approach would be to first load smaller thumbnail images and then with a delay load the fullscreen image.