Skip to content

Commit

Permalink
Start and stop location tracking in iOS depending on registration status
Browse files Browse the repository at this point in the history
  • Loading branch information
robo-w committed Dec 27, 2019
1 parent 385aaeb commit 814e4c8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
25 changes: 21 additions & 4 deletions GeoClient/GeoClient.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

using Foundation;
using Foundation;
using GeoClient.Services.Registration;
using UIKit;

namespace GeoClient.iOS
Expand All @@ -8,8 +8,16 @@ namespace GeoClient.iOS
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IGeoRegistrationListener
{
private readonly LocationManager _locationManager;

private AppDelegate()
{
RegistrationService.Instance.RegisterListener(this);
_locationManager = new LocationManager();
}

//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
Expand All @@ -23,9 +31,18 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary options)
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
LoadApplication(new App());

new LocationManager().StartLocationUpdates();

return base.FinishedLaunching(app, options);
}

public void GeoServerRegistered()
{
_locationManager.StartLocationUpdates();
}

public void GeoServerUnregistered()
{
_locationManager.StopLocationUpdates();
}
}
}
6 changes: 6 additions & 0 deletions GeoClient/GeoClient.iOS/LocationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public void StartLocationUpdates()
}
}

public void StopLocationUpdates()
{
Console.WriteLine("Requesting stop of location updates from underlying location manager.");
_manager.StopUpdatingLocation();
}

private void InformRegistryAboutLocationUpdate(CLLocation lastLocation)
{
Location updatedLocation = CreateXamarinLocation(lastLocation);
Expand Down
7 changes: 1 addition & 6 deletions GeoClient/GeoClient.iOS/Main.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;
using UIKit;

namespace GeoClient.iOS
{
Expand Down
10 changes: 0 additions & 10 deletions GeoClient/GeoClient/Services/IDataStore.cs

This file was deleted.

2 changes: 0 additions & 2 deletions GeoClient/GeoClient/Services/Utils/AsyncHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down

0 comments on commit 814e4c8

Please sign in to comment.