ambient-light
ambient-light copied to clipboard
Ambient light map styling with the Mapbox iOS SDK
Ambient Light Mapbox iOS Demo
Mapbox Maps SDK for iOS demo app that demonstrates ambient light-based map styling.

Getting started
- Run
pod installto download the Mapbox iOS SDK via Cocoapods - Open
ambient-light.xcworkspacein Xcode - Insert your Mapbox access token in
AppDelegate.m - Build amazing cartographic things
Detecting ambient light
This is a bit of a lie: Apple does not expose any direct ambient light sensing API to developers, so this demo uses screen brightness as a proxy.
This relies on the user having auto brightness enabled, which isn’t always a given (and there’s no easy way to detect if that’s on, either).
Generally this technique works well and is the same that’s used in Tweetbot.
How the UI works
The slider controls the screen brightness threshold at which the map will change styles — e.g., farther left will switch to the dark style at a lower screen brightness.
A reasonable threshold is about 35%, or somewhat left of center.
Current brightness is indicated by a vertical line on top of the slider bar.

Does not work in simulator
This does not really work in the simulator as brightness is hardcoded to 50%, but you can still drag the slider to change styles.
Need help?
If you haven’t already, read the official project overview from Mapbox and have a look at the API reference. The Mapbox tag on Stack Overflow is a great place to ask questions (that are often answered by Mapboxers). Mapbox also offers tons of help resources.
Found a bug?
If you’ve found a bug in the Mapbox Maps SDK for iOS, please take a bit to report it on the project repo.