1.請求權限
PHPhotoLibrary.requestAuthorization
2.需要的資料型態
PHAsset.fetchAssetsWithMediaType
3.取得全部圖片
enumerateObjectsUsingBlock
Code:
PHPhotoLibrary.requestAuthorization { [weak self] (status) in
// UI Thread
dispatch_async(dispatch_get_main_queue(), {
let images = PHAsset.fetchAssetsWithMediaType(.Image, options: nil)
images.enumerateObjectsUsingBlock({ (obj, index, stop) in
guard let weakSelf = self else {
return
}
let item = ArrayCollectionViewCellViewModel()
item.assets = obj as? PHAsset
weakSelf.cellViewModel.append(item)
})
})
}
參考資料:
https://github.com/shinobicontrols/iOS8-day-by-day
http://stackoverflow.com/questions/26065774/which-phassetcollection-to-use-for-saving-an-image
留言列表