13 August 2008

Reading location

The API to read location data from an application is nice and easy.
However, to help the user know what's going on, the iPhone will prompt for the user to allow an application to see location data, at least the first couple of times it runs. Interestingly enough, this also happens if an otherwise non-GUI application attempts to read the location.
The application name it puts in quotes is taken from the "CFBundleIdentifier" string in the local directory's Info.plist file. The program will basically freeze until the alert is dismissed by the user (if the user hits "Don't Allow", the program receives an error on the callback).
It seems that most location-savvy apps will only cause the OS to prompt the user on the first two consecutive runs. For a while I thought this wasn't happening for my jailbroken app, but the trick was to ensure that you tell the location manager to stop sending updates.
The apps that locationd (the system process that exposes location services) has seen seem to be stored in /private/var/mobile/Library/Preferences/com.apple.locationd.plist, though this doesn't seem to store the information about when they can be run without prompting the user.