Home / Topic / A way to check Photo Library access?

A way to check Photo Library access?

Home Kwiksher Forums Kwik4 A way to check Photo Library access?

Viewing 12 posts - 1 through 12 (of 12 total)
  • #85998

    Is there a way to check if the user has allowed Photo Library access? When using a Canvas, the Take Screenshot function will put up an alert letting the user know that the image has been stored in their library, but that same alert will pop up even if the user has not allowed access to their Photo Library. Is there any way for the app to determine access and not put up the alert if no access was allowed? Or to put up another alert that says something different (for example, “Your image cannot be saved without access to your Photo Libbrary”?)


    An external code with media.hasSource() will work. I have not used it yet. Let’s see how it is. I will test it tomorrow.



    Thank you.


    I added a permission check in components/pageXXX/page_screenshot.lua. You can download the following files from the github


    Please replace the files in tmplt folder.


    I downloaded these files, but now my app is crashing with errors in random action files and cannot start.


    Nevermind. I was downloading from the links when I needed to go to github and copy the code.


    I tested this and it works on the Windows simulator, but does not work on the Mac simulator or on the device. Both my Mac and my Ipad return the same “Saved” message instead of the customized “No permission”.


    I debugged for an hour and you are right. the permission check is not working. In iOS/Mac does not return false with media.hasSource, even user denied the access.


    Maybe I am missing something, I will try tomorrow again. It is an issue of media.hasSource()



    The first time you run an app after a fresh install, media.hasSource( media.PhotoLibrary ) would always return true. This is by design as iOS permissions have a “not determined” state that they’re initialized to when an app is run the first time.

    By returning true that first time, your Lua app could continue to whatever behavior needs permission, and the OS can request that permission when necessary.


    page_screenshot.lua is updated

    Wrong: media.photoLibrary
    Correct: media.PhotoLibrary

    I tested it with iPad but the result is not changed. media.hasSource(media.PhotoLibrary) always return true. There is no way to check user rejected the permission request. Nor no method to know the screenshot file is saved or not.

    I will look into Corona’s runtime source codes.


    I found that after I installed the the page_screenshot.lua and actionX_lua files above, I had an error with the screenshot where elements I had hidden suddenly became unhidden after the screen shot. I think the problem is something in the actionX.lua, but I decide to just restore the version of both files from the last template update. That fixed things.

    I further decided to just comment out the nativeShowAlert from the page_screenshot_.lua so that no alert will pop up about the saved image. I already have a dialogue box within the app that asks if the user wants to save the screenshot, so I will just leave it like that for now.


    >comment out the nativeShowAlert from the page_screenshot_.lua so that no alert will pop up

    That’s good workaround. I will revise actionX.lua in gitHub. It is not yet migrated into Kwik.

    I found it in Corona source code not handle an error when saving an image to PhotosAlbum

    UIImageWriteToSavedPhotosAlbum( image, nil, nil, nil )

    Also the following discussion about a plugin to use UIImageWriteToSavedPhotosAlbum. The plugin code looks good.


    I could use to make a saving screenshot plugin for Kwik or modify directory Corona source. Either way, it takes some time.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.