开发者

How to get coordinates when iPhone is locked/sleeping?

开发者 https://www.devze.com 2022-12-30 12:57 出处:网络
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 lo

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

精彩评论

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