Telerik-Verified-Plugins / ImagePicker

Cordova Plugin For Multiple Image Selection
MIT License
182 stars 331 forks source link

Crashes on IOS when we deny the permissions. (DONT ALLOW) #124

Open shafiqshams opened 6 years ago

shafiqshams commented 6 years ago

The issue is very clear on iOS, that for the very first time I want to upload images and open my gallery, If the user denies the permission popup (Don’t Allow) the App crashes.

This issue is on iOS only. Need an urgent fix. Please help! TIA.

quangpdt commented 6 years ago

Hi @ShafiqEssani. Not sure but if you're still stuck with this, I took a look into plugin iOS code and found they never return failure callback, just logging some message to XCode. I created the pull request here, you can take a look: https://github.com/Telerik-Verified-Plugins/ImagePicker/pull/130

furaiev commented 6 years ago

Hi @quangpdt. Unfortunately it still crash the app GMImagePicker: User pressed cancel button 2018-07-21 16:09:31.261620+0300 docker[1875:565127] [Generic] This application is not allowed to access Photo data. ( 0 PhotoLibraryServices 0x27ccbf9d + 1396 1 Photos 0x287e8aa9 + 62 2 libdispatch.dylib 0x00c34453 _dispatch_client_callout + 22 3 libdispatch.dylib 0x00c34f4f dispatch_once_f + 86 4 Photos 0x287e8a67 + 132 5 Photos 0x287c028d + 134 6 Photos 0x287d69d5 + 180 7 libobjc.A.dylib 0x1d419259 + 238 8 docker 0x00104c71 -[GMAlbumsViewController .cxx_destruct] + 40 9 libobjc.A.dylib 0x1d3fe053 + 116 10 libobjc.A.dylib 0x1d4096ad objc_destructInstance + 34 11 libobjc.A.dylib 0x1d4096cd object_dispose + 14 12 UIKit 0x2372c5a7 + 138 13 UIKit 0x235240f7 + 1734 14 UIKit 0x2358e8df + 220 15 docker 0x0010212b -[GMAlbumsViewController dealloc] + 160 16 CoreFoundation 0x1e1691bb + 154 17 CoreFoundation 0x1e08cc85 + 14 18 libobjc.A.dylib 0x1d419259 + 238 19 UIKit 0x235240cd + 1692 20 UIKit 0x2352e629 + 464 21 docker 0x001108a3 -[GMImagePickerController .cxx_destruct] + 40 22 libobjc.A.dylib 0x1d3fe053 + 116 23 libobjc.A.dylib 0x1d4096ad objc_destructInstance + 34 24 libobjc.A.dylib 0x1d4096cd object_dispose + 14 25 UIKit 0x2372c5a7 + 138 26 UIKit 0x235240f7 + 1734 27 docker 0x0010e953 -[GMImagePickerController dealloc] + 62 28 libobjc.A.dylib 0x1d4197a1 + 612 29 CoreFoundation 0x1e084f49 _CFAutoreleasePoolPop + 16 30 CoreFoundation 0x1e131e23 + 858 31 CoreFoundation 0x1e0851af CFRunLoopRunSpecific + 470 32 CoreFoundation 0x1e084fd1 CFRunLoopRunInMode + 104 33 GraphicsServices 0x1f82fb41 GSEventRunModal + 80 34 UIKit 0x2340da53 UIApplicationMain + 150 35 docker 0x00039d35 main + 50 36 libdyld.dylib 0x1d8724eb + 2 ) 2018-07-21 16:09:31.263245+0300 docker[1875:565127] Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'This application is not allowed to access Photo data.' *** First throw call stack: (0x1e177b3d 0x1d3ff067 0x27ccc025 0x287e8aa9 0xc34453 0xc34f4f 0x287e8a67 0x287c028d 0x287d69d5 0x1d419259 0x104c71 0x1d3fe053 0x1d4096ad 0x1d4096cd 0x2372c5a7 0x235240f7 0x2358e8df 0x10212b 0x1e1691bb 0x1e08cc85 0x1d419259 0x235240cd 0x2352e629 0x1108a3 0x1d3fe053 0x1d4096ad 0x1d4096cd 0x2372c5a7 0x235240f7 0x10e953 0x1d4197a1 0x1e084f49 0x1e131e23 0x1e0851af 0x1e084fd1 0x1f82fb41 0x2340da53 0x39d35 0x1d8724eb) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

quangpdt commented 6 years ago

@furaiev: Which version are you using now? My pull request is merged to master and the author already released new version with this fix. You can install the latest version and try again. Hope that helps.

furaiev commented 6 years ago

Hi, @quangpdt, I use the latest "@ionic-native/image-picker": "^4.7.0",

quangpdt commented 6 years ago

@furaiev:

You must update the native plugin first, try this: "cordova-plugin-telerik-imagepicker": "^2.2.2",. Here is my implementation for checking permissions before requesting images from Photo:

createPicturesFromLibrary(savePath: string): Promise<string[]> {
    return this.imagePicker.hasReadPermission()
        .then(hasReadPermission => {
            if (hasReadPermission) {
                return this.imagePicker.getPictures(({
                    disable_popover: true
                }) as any).then((fileURIs) => {
                    //TODO: Do something with returned fileURIs
                });
            } else {
                return this.imagePicker.requestReadPermission()
                    .then(() => this.createPicturesFromLibrary(savePath))
                    .catch((error) => {
                        if (_.isEqual(error, "Access has been denied. Change your setting > this app > Photo enable") ||
                            _.isEqual(error, "Access has been restricted. Change your setting > Privacy > Photo enable")) {
                            //TODO: Handle error caused by permission
                        }
                        return Promise.reject(error);
                    });
            }
        })
}

My implementation is only applied for iOS platform so please revise before using it on other platforms although I think it should work.

nathanlemos commented 5 years ago

Same error on Android. I tried the @quangpdt 's solution, but when I select the box "Don't ask again" and clicked at deny button, the app stuck on my screen and blocked me to do any action

konnectappdev commented 5 years ago

@quangpdt This way it never asks for permission? It seems to trigger the catch of the requestReadPermission the first time you trigger this function (which in my case will open the native settings menu. Why doesnt the requestReadPermission callback trigger when a user actually selects an option in the pop up?

Edit: It seems i spoke to soon. When you're testing your app it seems to remember your settings (sometimes) and this caused the plugin to never enter the "permission unknown" stage since it was either true or false. Tried a new device and it worked perfectly ( using a different app id should also work) however it would be nice for Apple to add a reset permissions option when developing mode is activated on your device