-1

I am new in IOS, I am using a third party library to integrate my multiple image/video picker. library link https://github.com/hyperoslo/Gallery

Local images/video displaying fast enough but the problem is once I am using the iCloud contain more than 500+ images it taking almost 1 mins. to load for the first time, is their any solution reduce or almost remove the loading time.

This is my code snapshot, might helpful

class MyGalleryViewController: UIViewController,     GalleryControllerDelegate,UITabBarControllerDelegate{
let gallery = GalleryController()
override func viewDidLoad() {
super.viewDidLoad()

    openGallery()     
}
private func openGallery(){
    gallery.delegate = self
    gallery.modalPresentationStyle = .fullScreen
    present(gallery, animated: true, completion: nil)
}
//Rest of galleryController function
}

Big big thanks in advance.

Ronak Amlani
  • 654
  • 7
  • 15

1 Answers1

1

There are steps you need to follow:

  • Get PHAsset for image on iCloud
 PHAsset.fetchAssets(with: .image, options: PHFetchOptions())
    // Images on iCloud will be included
  • Request image for assets
let imageRequestOptions = PHImageRequestOptions()
imageRequestOptions.deliveryMode = .opportunistic
imageRequestOptions.isNetworkAccessAllowed = true // allowing iCloud image downloaded from network
imageRequestOptions.progressHandler = progressHandler // progressHandler is outer callback, may be called multiple times

PHCachingImageManager.default().requestImage(for: asset)
  • In PHAssetImageProgressHandler handle image download progress
let progressHandler: PHAssetImageProgressHandler = { (progress, _, stop, _) in
    cell.updateProgress(CGFloat(progress))
}

The key to iCloud image:

  1. PHImageRequestOptions.isNetworkAccessAllowed
  2. PHImageRequestOptions.progressHandler
Community
  • 1
  • 1
Rango
  • 21
  • 5
  • Thanks Rango, for the quick answer, but I am confuse how I can configure "PHImageRequestOptions" with the Gallery library? – Ronak Amlani Apr 17 '20 at 12:28
  • There is a PHImageRequestOptions(). Check line 18, "UIImageView+Extensions.swift" of Gallery source file. you can modify the options and add progressHandler to handle download progress by yourself. – Rango Apr 20 '20 at 02:55
  • Thanks, I will definitely try it. :) – Ronak Amlani Apr 21 '20 at 11:20