Skip to content

Commit

Permalink
Merge pull request #152 from nohana/feature/uploading_issue_due_to_de…
Browse files Browse the repository at this point in the history
…selecting_photos_on_system

Fixed a dropping asset issue after changing selected photos on the system setting.
  • Loading branch information
Noodlekim authored Aug 25, 2022
2 parents cfc0c64 + c2475c1 commit a4507d2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions NohanaImagePicker/AssetListSelectableDateSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,22 @@ extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver
func photoLibraryDidChange(_ changeInstance: PHChange) {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }

var removedAssets: [PhotoKitAsset] = []
self.nohanaImagePickerController.pickedAssetList.forEach { item in
if let asset = item as? PhotoKitAsset, let changeDetail = changeInstance.changeDetails(for: asset.asset) {
if changeDetail.objectWasDeleted {
removedAssets.append(asset)
}
}
}
for removedAsset in removedAssets {
self.nohanaImagePickerController.dropAsset(removedAsset)
}
if !removedAssets.isEmpty {
self.setToolbarTitle(self.nohanaImagePickerController)
}

self.photoKitAssetList = PhotoKitAssetList(album: self.photoKitAssetList.assetList, mediaType: self.photoKitAssetList.mediaType, ascending: false)
self.dateSectionList = AssetDateSectionCreater().createSections(assetList: self.photoKitAssetList.assetList, options: PhotoKitAssetList.fetchOptions(self.photoKitAssetList.mediaType, ascending: false))
self.isLoading = false
Expand Down

0 comments on commit a4507d2

Please sign in to comment.