Posts tagged ios
Using the iOS Ambient Light Sensor in Unity

Our Seer Stone app, available for both iOS and Android, uses the ambient light sensor to trigger certain interactions. Unity provides direct support for the ambient light sensor in Android, but iOS is unfortunately still unsupported at the time of writing. Apple can’t imagine any profitable reason to provide you with access to such a thing and by extension Unity can’t implement it.

Seer Stone works by revealing secrets to the user only when they close out the surrounding light from the physical device. The app instructs users to put their device into something they can look into while closing out the surrounding light. We recommend putting your phone into your top hat, which you surely own. ou could, of course, use anything; a pillow case, your t-shirt pulled up over your head, get under a blanket, etc. Or, if you lack whimsy and color in your life you can just cover the front-facing sensor cluster on your phone with your thumb.

Supporting iOS presents a problem for this concept as any app accessing the ambient light sensor will be rejected from the app store. So how did we get around this limitation to make our app work?

In order to get the brightness of the scene, we access the front facing camera. Apple won’t give you the ambient light, but they will give you an estimation of the scene brightness of the image coming through a device camera. There are some subtle differences between how this method would work vs. ambient light, but it’s more than good enough for out purposes.

Unfortunately you will have to request camera permissions, which sucks if you don’t otherwise need those permissions. In my case, there are other features that use the external cameras so asking for permissions makes more sense.

This maybe seems straightforward for the genius developers out there, but it took my feeble brain a good long while to come up with. Being proud enough of my solution, I decided to release it as an asset on the Unity Asset store. Also, I had to pay another developer to write the swift code to make all this work so I’m wondering if it’s possible to actually recover my investment.

I priced the asset on the asset store at $20. I thought about it like this: how much would I be willing to pay to avoid the number of hours involved in solving this problem? I buy assets all the time if the math makes senes. I could recreate this function myself in 30 hours, or I could just buy an asset for $20. As an indie dev I think the economics make sense.

Our development philosophy is to go for what is maximally unexpected. We want to take all the sensors and information available to create an entirely unique and surprisingly contextual interaction in an unexpected way. There are infinite ways to do a thing and the normal way can be a surprisingly narrow paradigm.


Sam Garfielddevlog, unity, ios