1
votes

I am developing an app in Xamarin Forms which will show thing live position of the user on a map and all the users having the app can track other users movement.

Right now the app is working fine in android. But in the iOS foreground, android background it stops after some time. It is not at all running in ios background when I put the app in the background it stops showing the location and stops fully.

Please share some idea to keep the app live in background and foreground mode for the whole day.

1
You need to share the code for your location service quite honestlyFreakyAli

1 Answers

0
votes

Generally speaking, mobile OSs will stop your apps, when they are in the background for some time. How strict the OSs are depends on the OS and the version. iOS has "always" been very strict about it, Android has been a bit more loose in older versions, but is quite restrictive in newer versions. Anyway, getting the location in background is quite a common use case and OSs are providing you options to do it nevertheless, if you ask them politely.

iOS

As of iOS 11, there is a distinction between updating the location when in use and when in background. The user can choose which one to grant and you'll have to handle it appropriately.

According to this guide you'll have to add the NSLocationAlways key to your Info.plist to contimue getting the location when in background.

Android

From the Android developer guide

In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.

Anyway

The system distinguishes between foreground and background apps. An app is considered to be in the foreground if any of the following is true:

  • It has a visible activity, whether the activity is started or paused.
  • It has a foreground service.
  • ...

According to this, you can create a foreground service, see here more about it

For this reason, foreground services must show a status bar notification with a priority of PRIORITY_LOW or higher, which helps ensure that the user is aware of what your app is doing.

So if you are starting a foreground service that is shown in notification bar, you should be able to retrieve updates, even if your apps main Activity is not in foreground.