iOS Permissions / How do I know if media.save( ) failed?

How can I tell if a call to media.save failed? There does not appear to be anything returned from the function itself, however there will be an error message in the log if the function failed.

Related, is there a way to test whether or not an iOS user has granted access to photos?

Cheers,

Ian

Hey Ian,

For media.save(), it definitely does not return any status as to whether it was successful or not. Whether that was a design decision or a bug I’m not sure of.

At the beginning of 2016, we implemented some extensions to existing Lua APIs to handle runtime permissions, but these APIs only work on Android at the moment. See the Introducing New Android 6 Features for more info on that.

In the specific case of checking whether an iOS user has granted access to photos, you should be able to use media.hasSource( media.PhotoLibrary ). The return values for this should be analogous to those for media.hasSource( media.Camera ).

It does look like our docs need updating on that, assuming it works for you.

Ah perfect, it looks like hasSource will do what I need it to. 

Thanks Ajay!

Looking back at this code, it looks like there’s a subtlety I forgot to mention. 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.

Hey Ian,

For media.save(), it definitely does not return any status as to whether it was successful or not. Whether that was a design decision or a bug I’m not sure of.

At the beginning of 2016, we implemented some extensions to existing Lua APIs to handle runtime permissions, but these APIs only work on Android at the moment. See the Introducing New Android 6 Features for more info on that.

In the specific case of checking whether an iOS user has granted access to photos, you should be able to use media.hasSource( media.PhotoLibrary ). The return values for this should be analogous to those for media.hasSource( media.Camera ).

It does look like our docs need updating on that, assuming it works for you.

Ah perfect, it looks like hasSource will do what I need it to. 

Thanks Ajay!

Looking back at this code, it looks like there’s a subtlety I forgot to mention. 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.