Skip to content

Commit eb4d9ea

Browse files
committed
fix: PHPhotoLibrary.shared().presentLimitedLibraryPicker dissmiss
1 parent f64a75a commit eb4d9ea

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

example/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function App() {
4949
singleSelectedMode,
5050
isCrop: true,
5151
usedCameraButton: false,
52-
mediaType: 'image',
52+
mediaType: 'video',
5353
});
5454

5555
const crop = response.crop;

ios/MultipleImagePicker.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ class MultipleImagePicker: NSObject, UINavigationControllerDelegate {
5858
}
5959
}
6060

61-
private func handleLimitedCondition() {
61+
private func fetchAssetCount() -> Int {
6262
let options = PHFetchOptions()
6363
options.predicate = NSPredicate(format: "mediaType = %d", config.mediaType != nil ?
6464
(config.mediaType == .image ? PHAssetMediaType.image.rawValue : PHAssetMediaType.video.rawValue) : PHAssetMediaType.unknown.rawValue)
6565
let fetchResult = PHAsset.fetchAssets(with: options)
66-
67-
if fetchResult.count == 0 {
66+
return fetchResult.count
67+
}
68+
69+
private func handleLimitedCondition() {
70+
let count = self.fetchAssetCount()
71+
if count == 0 {
6872
self.presentLimitedController()
6973
} else {
7074
self.navigatePicker()
@@ -78,9 +82,12 @@ class MultipleImagePicker: NSObject, UINavigationControllerDelegate {
7882
let topViewController = self.getTopMostViewController()!
7983
var show = 0
8084

81-
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: topViewController) { log in
82-
if(log.isEmpty){
83-
topViewController.dismiss(animated: true)
85+
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: topViewController) { _ in
86+
let count = self.fetchAssetCount() // check count after presentLimitedLibraryPicker
87+
if count == 0 {
88+
topViewController.dismiss(animated: true) {
89+
self.reject("LIMITED_ACCESS_CANCELLED", "User has canceled", nil)
90+
}
8491
return
8592
}
8693

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@baronha/react-native-multiple-image-picker",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
44
"description": "react-native-multiple-image-picker enables application to pick images and videos from multiple smart album in iOS/Android, similar to the current facebook app.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)