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”?)

    Yamamoto
    Keymaster
    #85999

    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.

    https://docs.coronalabs.com/api/library/media/hasSource.html

    #86000

    Thank you.

    Yamamoto
    Keymaster
    #86003

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

    https://github.com/kwiksher/kwik4tmplt/blob/master/components/pageXXX/page_screenshot.lua
    https://github.com/kwiksher/kwik4tmplt/blob/master/commands/pageXXX/actionX_.lua

    Please replace the files in tmplt folder.

    #86004

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

    #86006

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

    #86008

    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”.

    Yamamoto
    Keymaster
    #86011

    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.

    https://docs.coronalabs.com/api/library/media/hasSource.html

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

    Yamamoto
    Keymaster
    #86012

    https://forums.coronalabs.com/topic/66741-ios-permissions-how-do-i-know-if-mediasave-failed/?p=345887

    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.

    Yamamoto
    Keymaster
    #86013

    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.

    #86016

    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.

    Yamamoto
    Keymaster
    #86019

    >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.

    https://forums.coronalabs.com/topic/58195-uiimagewritetosavedphotosalbum-unable-to-callback-to-lua/

    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.