SHARE
TWEET

Untitled

a guest Sep 16th, 2019 118 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static func getImages(result: @escaping FlutterResult) {
  2.  
  3.         print("getImages")
  4.  
  5.         var photos : Array<String> = []
  6.  
  7.         let fetchOptions = PHFetchOptions()
  8.  
  9.         let allPhotos : PHFetchResult<PHAsset>? = PHAsset.fetchAssets(with: .image, options: fetchOptions)
  10.  
  11.         allPhotos?.enumerateObjects({ (object, count, stop) in
  12.  
  13.             print(count)
  14.  
  15.             let url : String? = self.getUrlAbsoluteString(photo: object)
  16.  
  17.             if url != nil {
  18.  
  19.                 photos.append(url ?? "")
  20.  
  21.             }
  22.  
  23.         })
  24.  
  25.         print("photos")
  26.  
  27.         print(photos)
  28.  
  29.         result(photos)
  30.  
  31.     }
  32.  
  33.    
  34.  
  35.     static func getUrlAbsoluteString(photo: PHAsset) -> String? {
  36.  
  37.         var result : String? = nil
  38.  
  39.         photo.getURL(completionHandler: { (URL) in
  40.  
  41.             print(URL)
  42.  
  43.             if URL != nil {
  44.  
  45.                 result = URL?.absoluteString ?? "";
  46.  
  47.             }
  48.  
  49.         })
  50.  
  51.         return result
  52.  
  53.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top