Integrating location tracking with Roam.ai's iOS SDK

Marc Kranendonk
Marc Kranendonk
Content Manager
July 22, 2024
In Short: Roam.ai's iOS location tracking software development kit lets you build location-aware apps for Apple devices. This lets your users experience premium location accuracy with minimum battery drain. In this article, we will be giving an introductory breakdown on the setting up, installation, and initialization process of our location SDK for those who haven't been to our docs page, or want a simplified overview.

Before we dive into the technical details, let’s briefly overview why working with a third-party location SDK is valuable. 

Why integrate Roam’s iOS SDK for location tracking?

Across the App Store, you’ll find an endless amount of mobile apps that use location technology, from retail, and delivery to ride-hailing. Applications from all sectors rely on location tracking to deliver a high-quality customer experience. The application marketplace is highly competitive, and retaining users is difficult when customer loyalty is thin. The build quality of your app matters as much as the service you provide. 

Using location features can be taxing on the mobile device. Apps that deliver location-reliant information can experience inaccurate data and high battery drain. This often happens when the device's GPS receiver delivers location information at an unnecessary rate. This also occurs because it’s the only IoT device that is used to determine a device’s location. 

On top of this, developing location-aware apps takes a long time when starting from scratch. Meeting a go-to-market deadline will be difficult when most of your time spent on research and development. A location SDK is a toolbox that not only provides the premium quality you are looking for but can help you get your app on the App Store on time.

Our iOS location tracking SDK lets you build location-aware apps with human-like location tracking while achieving minimal battery drain for iPhone users. It’s a customizable SDK built to understand human behavior, allowing you to integrate tracking modes and features that best fit your app needs.

Getting started with Roam’s location SDK for iOS

To integrate location tracking you’ll need to create a Roam account. This can be done for free without a credit card. Once you’ve set that up, you must create an iOS project on our dashboard. 

  1. Name the project however you wish and select “Roam SDK for iOS” as your project type. 
  2. To initialize the SDK, you’ll need the SDK_KEY which can be found under your project settings. 
  3. Once you have that key you are ready to integrate the SDK into your iOS application. 

With that said, the Roam iOS SDK requires Xcode 10.0 or later and is compatible with apps targeting iOS version 10 and above.

To do that, open Xcode and navigate to File > New Project. This will allow you to create a new project where you can begin developing your app.

Next, you'll need to configure the Info.plist file, which is the information property list that contains key data about your app. Specifically, you should add an XML snippet to this file. This snippet will include strings for NSLocationWhenInUseUsageDescription to inform users why your app needs location permissions while in use. If your app also requires background location tracking, be sure to add strings for NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription to explain the need for these permissions to your users.

After that, you need to enableBackground fetch and Location updates, which can be found under Project Setting > Capabilities >  and Background Modes.

Right, with Xcode setup now let's get into the SDK installation 

iOS location SDK installation

There are several ways Roam’s mobile location SDK can be installed for iOS. For the sake of keeping things straightforward, we’ll be going over the two most common methods:

  • Swift Package Manager
  • CocoaPods

Swift Package Manager

Swift Package Manager comes bundled with Xcode, making it easy to add the AWS SDK to your iOS project. To begin, open your project in Xcode and navigate to File > Swift Packages > Add Package Dependency.

In the search bar, enter the URL for the Roam SDK for iOS Swift Package Manager GitHub repository: https://github.com/roam-ai/roam-ios, and click “Next”. 

You will then see the repository rules for the SDK version you want to install. Choose the first rule, “Version”, and select “Up to Next Minor” to ensure that the latest compatible version from the main branch is used. Click “Next” to proceed.

Select roam-ios from the list and click “Finish”. If you need to modify the Swift Package Manager packages included in your project later, you can do so by opening the Swift Packages tab. Click on the Project file in the Xcode navigator, select your project's icon, and then choose the Swift Packages tab.

CocoaPods Installation

Adding the SDK project using Cocoapods is a bit simpler. First, you will open your Podfile and add the following line: pod “roam-ios”. 

Next, run “pod install” in your terminal. This command will integrate the Roam SDK and its dependencies into your project. The Roam SDK relies on CoreLocation, AWSMobileClient, and AWSIoT to fetch and transmit locations to our servers. Remember, the SDK is compatible with iOS 10 and above.

How to install the SDK manually 

If you don’t want to use CocoaPods and want to install manually, here is a brief overview from our docs page:

Initializing the Roam SDK for iOS

Our SDK offers a flexible method of initialization, allowing you to integrate our services into your application with ease. In our latest update, we’ve introduced a new setup approach using property list files (plist). Essentially, this removes the need for additional code. Here’s another snippet from our docs page to give you a more detailed overview of that process:

Request permissions for location tracking

For location tracking to work, you’ll need permission from the user otherwise your app won’t have access to their location info. You’ll have to import CoreLocation at the top of AppDelegate file. You’ll then need to make the declaration for Location Manager and add this line before the return statement in application(_:didFinishLaunchingWithOptions:) With this line, you ask users to allow the app to access location data both in the background and the foreground.

Location tracking using Roam.ai's iOS SDK

Should all the previous steps be completed you will be able to start location tracking with our SDK. Congratulations! Now you can build a mobile app with premium location features and minimal battery drain.

What you need to do next is use the Roam.startTracking method and specify the tracking mode you’d like to use.

Roam.ai tracking modes for iOS

There are three default tracking modes along with a custom tracking mode option which you can use depending on the needs of your app. 

The frequency of location updates desired defines these modes. The type of tracking mode that you use will determine the amount of battery required to perform it.  

  • Active: Our most intense tracking mode on offer that delivers location updates every 25 - 250 meters. Most commonly used by ride-hailing and fitness apps. It requires approximately 6 -12% of the battery, depending on the active period. 
  • Balanced: This tracking mode delivers location updates every 50 - 500 meters and requires 3-6% of battery to perform. Optimal for on-demand services like delivery apps. 
  • Passive: Our passive tracking mode uses 0-1% of the battery to pick up locations every 100 - 1000 meters. Ideal for social apps that use location features to allow users to share their location for brief periods. 

You can also define the method of location updates either through distance or time intervals. The distance and time intervals can be customized based on your choice of meters and seconds respectively. 

With that, we’ve covered the basics of integrating location tracking using Roam iOS SDK. The in-depth step-by-step guide can be found on our docs page. Over there you’ll be able to see the example codes, screenshots, and examples of how you can quickstart your location tracking.  

Want to know what we do at Roam

If you’re looking to build location-aware mobile apps and utilize location technology, contact our team or sign up to our dashboard and discover how to build your app with Roam.ai’s Location SDK and APIs today.

Unlock Location Technology

Guide
Marc Kranendonk
Marc Kranendonk
Content Manager
July 22, 2024