One Step, Two Step, Three Step
Occasionally you might need to track your customers location coordinates in real-time. You could build an app, but given that iOS and Android are supported by separate programming languages, following that route would mean implementing the code base twice...however, there is a way around that...
Xamarin (originally termed "mono"), allows cross-platform implementations for iOS, Android and Windows Mobile using C# .Net.
"With a C#-shared codebase, developers can use Xamarin tools to write native Android, iOS, and Windows apps with native user interfaces and share code across multiple platforms, including Windows and macOS."
For today's implementation, we're going to focus on Xamarin.iOS. Let's begin by creating a class to handle the geo location events.
Next, we need a LocationManager class that can handle the geo location event updates. Inside our class we need an instance of the CLLocationManager, and a delegate to handle the events.
Next we add a method for starting the location updates and the accuracy configuration.
We then need to set some initial permissions, which happen to be different for iOS 8 vs. iOS 9...
Now to configure everything to run in our LocationManager's constructor.
Now to put our LocationManager to use in a ViewController with an instance of the class.
Next, we need a method for subscribing to he location updates, and one for unsubscribing when the app enters background mode also.
Now in our ViewController's constructor, we can execute our method call to start the geo location updates.
Before we run our implementation, we need to configure the background mode to allow Geo Location updates (via the info.plist).
Following this, some additional privacy requirements are needed, to ensure we ask our user to allow the geo location updates to occur whilst using the app.
Finally, let's run our iOS app.
Click to allow the permissions as requested by the app...
Download Github Code Sample
Feel free to DOWNLOAD the sample code of the aforementioned implementation from my Github account.
Subscribe to Simon Gilbert Developer Blog
Get the latest posts delivered right to your inbox