开发者

How to get coordinates when iPhone is locked/sleeping?

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 coor开发者_运维知识库dinates during the locked period.

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

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜