Alternative to startMonitoringSignificantLocationChanges?

后端 未结 2 504
自闭症患者
自闭症患者 2021-01-06 07:55

I\'m somewhat a beginner to iPhone app development, but I\'m trying to make an app that basically updates your location every once a while when it\'s not in the foreground,

2条回答
  •  孤街浪徒
    2021-01-06 08:11

    Read the background location documentation on the Apple site here

    One option you have is to declare your app as requiring continuous location updates.

    An application can declare itself as needing continuous background location updates. An application that needs regular location updates, both in the foreground and background, should add the UIBackgroundModes key to its Info.plist file and set the value of this key to an array containing the location string. This option is intended for applications that provide specific services, such as navigation services, that involve keeping the user informed of his or her location at all times. The presence of the key in the application’s Info.plist file tells the system that it should allow the application to run as needed in the background.

    This will have the desired result in that your app will be able to track where the user walks, however you need to be aware that this is the most power hungry option and it is generally regarded as the least desirable option. However if you are trying to track someone's walk, this is the sort of thing you need to do.

    HOWEVER. You say you only want to get updates every 10 mins or so. In that case you are best NOT to use this strategy and instead use significant location updates. These WILL restart your app if it is closed but as you say, they are not very accurate. The trick to making them better is to start normal location updates as soon as the app gets the significant location update and you should get enough time for that to improve your location (by sending you some more updates) before the app is suspended again.

    It won't be perfect, but it will be better than just using significant (ie cell tower) changes.

提交回复
热议问题