Location tracker app pauses in background after a few minutes
I am trying to build a location tracking app. The application must be running in the background . So I turn on the properties "Include Background Modes", "Location Updates" and added the "NSLocationAlwaysUsageDescription" parameter to the source.
On iOS7 the app works fine, but on ios8 it pauses in the background after a few minutes (how the app is supposed to work: I send a request every time a new location is received and if I can see this request on the server it means the app is running ).
I downloaded the xamarin.mobile component with location function and used it instead of my class for geolocation. The app also pauses in the background.
I created an Objective-C application with the same functionality and tested it on the same device. Result - the application works fine (as expected).
So maybe the app still needs some tweaking or am I missing something?
public class LocationUpdatedEventArgs : EventArgs
{
CLLocation location;
public LocationUpdatedEventArgs(CLLocation location)
{
this.location = location;
}
public CLLocation Location
{
get { return location; }
}
}
protected CLLocationManager locMgr;
public event EventHandler<LocationUpdatedEventArgs> LocationUpdated = delegate { };
public GeoLocationService_iOS()
{
this.locMgr = new CLLocationManager();
LocationUpdated += SaveLocation;
locMgr.AuthorizationChanged += (object sender, CLAuthorizationChangedEventArgs e) =>
{
//CheckStatus();
};
if (locMgr.RespondsToSelector(new Selector("requestAlwaysAuthorization")))
{
locMgr.RequestAlwaysAuthorization();
}
locMgr.DistanceFilter = 1;
locMgr.DesiredAccuracy = CLLocation.AccuracyBest;
locMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
{
// fire our custom Location Updated event
this.LocationUpdated(this, new LocationUpdatedEventArgs(e.Locations[e.Locations.Length - 1]));
};
locMgr.StartUpdatingLocation();
}
public void SaveLocation(object sender, LocationUpdatedEventArgs e)
{
SendLoc();
}
source to share