views:

157

answers:

2

For normal situations, the didUpdateToLocation (of CLLocationManager) does not work any more when the lock/sleep button is pushed, and your app cannot get further newLocation coordinates during the locked period.

However, some apps CAN track during the locked period, and they will show the correct route when you unlocked and see the Mapview. Obviously there are ways to get the coordinates during the locked period.

How to get the coordinates when the iPhone is locked/sleeping?

Who has hints and further info, please post. Thanks.

+1  A: 

When the iPhone locked it (quickly but not instantly) enters a deep sleep which stops everything. In order to prevent deep sleep, there is a trick...

Play a silent sound every 5 seconds. (Honest!) Set up a tiny silent wav (or whatever format) file and play it on a timer. The phone will never enter deep sleep and CLLocationManager will continue to function as expected.

Andiih
Thanks a lot for this interesting trick! I am reading this thread now: http://www.iphonedevsdk.com/forum/iphone-sdk-development/39150-playing-silent-sound-keep-away-deep-sleep.html
lionfly
the DeepSleepPreventer code looks very much like the code I used. It does work, inspite of some of the comments in that article.
Andiih
A: 

Another way of doing it in iOS4+, without using the playing-silent-sound method:

Add

<key>UIBackgroundModes</key>
    <array>
        <string>location</string>
    </array>

in your info.plist. For details: UIBackgroundModes

lionfly