Mapbox Maps SDK for iOS demo app that demonstrates ambient light-based map styling.
- Run
pod install
to download the Mapbox iOS SDK via Cocoapods - Open
ambient-light.xcworkspace
in Xcode - Insert your Mapbox access token in
AppDelegate.m
- Build amazing cartographic things
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.
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.
This does not really work in the simulator as brightness is hardcoded to 50%, but you can still drag the slider to change styles.
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.
If you’ve found a bug in the Mapbox Maps SDK for iOS, please take a bit to report it on the project repo.