2016-09-27 41 views
0

您好我不得不迅速從2切換到3迅速如何從照片庫中獲取圖像?

這裏是我的uploadVC

class PhotoUploadVC: UICollectionViewController { 


    fileprivate var assets: PHFetchResult<AnyObject>? 
    fileprivate var sideSize: CGFloat! 

//這是viewDidLoad中的片斷()

override func viewDidLoad() { 
     super.viewDidLoad() 


     //Navigation Config 
     self.navigationItem.title = "CAMERA ROLL" 




     if PHPhotoLibrary.authorizationStatus() == .authorized { 
      reloadAssets() 
     } else { 
      PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) -> Void in 
       if status == .authorized { 
        self.reloadAssets() 
       } else { 
        self.showNeedAccessMessage() 
       } 
      }) 
     } 



    } 

//這裏是函數約取圖像

fileprivate func showNeedAccessMessage() { 
     let alert = UIAlertController(title: "Image picker", message: "App need get access to photos", preferredStyle: .alert) 

     alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction) -> Void in 
      self.dismiss(animated: true, completion: nil) 
     })) 

     alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction) -> Void in 
      UIApplication.shared.openURL(URL(string: UIApplicationOpenSettingsURLString)!) 
     })) 

     self.show(alert, sender: nil) 
    } 

    fileprivate func reloadAssets() { 
//  activityIndicator.startAnimating() 
     assets = nil 

     collectionView?.reloadData() 
     let fetchOptions = PHFetchOptions() 
     fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] 
     assets = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: fetchOptions) 



     collectionView?.reloadData() 


//  activityIndicator.stopAnimating() 
    } 

enter image description here

我收到了上面的錯誤消息。

問題在哪裏?

我認爲「fileprivate var assets:PHFetchResult?」

有人幫助我嗎?

回答

1

嘗試改變:

fileprivate var assets: PHFetchResult<AnyObject>? 

var assets: [AnyObject]! 
相關問題