iOS
Last updated
Was this helpful?
Last updated
Was this helpful?
The Roam iOS SDK enables continuous, battery-efficient location tracking in iOS apps. This guide walks you through integrating the SDK — from installation to receiving real-time updates — with an optional setup for batch sync and data enrichment.
Before you begin:
Access to the
A project created with your app’s Bundle ID
Your PUBLISHABLE_KEY from the dashboard
Xcode 14.0 or later
iOS 12+
Already set up your project on the dashboard? If not, follow the instructions in the section.
Important: Make sure your Bundle ID matches exactly with the one added on the Roam Dashboard. The SDK will not initialize if they differ.
The first step in integrating the Roam iOS SDK is to add the necessary dependencies to your project using CocoaPods. This ensures that your app can download and link the SDK from Roam’s hosted repository.
Open your project’s Podfile
and add the following line:
In your terminal, navigate to your project directory and run:
Once installed, open the .xcworkspace
file to continue development.
Open your AppDelegate.swift
and import the SDK at the top of the file:
🧪 Test Tip: Try typing
Roam.
in any Swift file — if Xcode shows method suggestions, the SDK was installed successfully.
After installing the SDK, the next step is to initialize it when your app launches. Initialization tells the Roam SDK which project it belongs to and prepares it to begin location tracking.
Open AppDelegate.swift
and update the application(_:didFinishLaunchingWithOptions:)
method as follows:
Replace "YOUR_PUBLISHABLE_KEY"
with the actual key from your Roam Dashboard.
Always call Roam.initialize(...)
inside didFinishLaunchingWithOptions
.
Calling it too early (like in a custom initializer or another part of the app lifecycle) may lead to tracking failures or errors like MotionStatus.ERROR_INITIALIZE
, especially on first launch.
🧪 Test Tip: Add a simple log after initialization to confirm it runs:
This log should appear in your Xcode console when the app starts.
To start tracking location, your app must request the appropriate permissions from the user. iOS supports various permission levels like When In Use and Always, and each affects how the Roam SDK behaves — especially in background scenarios.
Open your Info.plist
and add the following keys and descriptions:
These strings are shown to users in system permission prompts.
You should call Roam.requestLocation()
only after the SDK has finished initializing. We recommend delaying it by a second or two to avoid race conditions on cold starts:
This method triggers the system dialog prompting the user to allow location access.
On first launch, iOS might not show the "Always" prompt. It often appears later — typically when background tracking is triggered for the first time.
🧪 Test Tip: Test on a real device. Simulators may not always show the correct behavior for background location or "Always" permissions.
Once the SDK is initialized and permissions are granted, you’re ready to start tracking location. This step covers how to begin and stop location tracking using Roam’s built-in methods.
To start tracking, call the Roam.startTracking()
method. This begins collecting location updates — optimized for both accuracy and battery life.
You can trigger tracking wherever it fits your flow (e.g., after login or when entering a specific screen):
We recommend using .balanced
tracking mode for a strong balance between battery life and update frequency. This is the default mode for most production use cases.
To stop tracking at any time (e.g., when the user logs out or tracking is no longer needed):
This is useful for scenarios such as:
User signs out of the app
You need location tracking only during specific workflows
You want to pause tracking during inactivity
🧪 Test Tip: Start tracking, then move around with the device (real or simulator). You should see location logs via the
RoamDelegate
method. Stop tracking and confirm that no additional updates are received.
Once tracking is active, the Roam SDK will begin delivering location updates to your app. To receive and handle these updates, your app must implement the RoamDelegate
protocol.
RoamDelegate
In your AppDelegate.swift
(or any other class you'd like to handle location updates), conform to the RoamDelegate
protocol:
Roam will keep delivering updates automatically in both foreground and background (depending on permission level and mode).
🧪 Test Tip:
Simulate location changes using:
Xcode > Debug > Simulate Location
A physical device while moving
A pre-recorded GPX file
Watch the Xcode console for printed updates from
didUpdateLocation
.
By default, the Roam SDK sends each location update in real-time. However, you can enable Batch Mode to buffer and transmit multiple location events together. This helps reduce network usage and battery drain — especially when the device is offline or in low-connectivity environments.
In your AppDelegate
or wherever you initialize the SDK, enable batch syncing with the following setup:
You can call setConfig(...)
anywhere after SDK initialization, such as after user login or when the app is active.
If you don’t want to send everything, you can manually select what data should be included:
All fields are optional — just toggle the ones your use case requires. See full field list in the Data Enrichment section.
To stop batching and return to real-time updates:
This will stop buffering and resume real-time location updates.
🧪 Test Tip: Simulate offline behavior by disabling Wi-Fi and mobile data. Then re-enable them after some time to observe batch sync behavior.
When Batch Sync is enabled, the Roam SDK includes a wide range of contextual metadata with each location update. This allows for more accurate analytics and deeper insights into user behavior, device state, and environmental conditions.
Below is the full list of fields that can be optionally included in each batched update. You can control which of these fields to include using the RoamBatchPublish
configuration.
1
Tracking Mode
tracking_mode
2
Latitude
latitude
3
Longitude
longitude
4
Speed
speed
5
Altitude
altitude
6
Course
course
7
Horizontal Accuracy
horizontal_accuracy
8
Vertical Accuracy
vertical_accuracy
9
Activity
activity
10
App Context
app_context
11
Recorded At
recorded_at
12
Timezone Offset
tz_offset
13
Battery Status
battery_status
14
Battery Remaining (%)
battery_remaining
15
Battery Saver
battery_saver
16
Network Status
network_status
17
Network Type
network_type
18
Network State
network_state
19
Location Permission
location_permission
20
GPS Status
gps_status
21
Device Model
device_model
22
Device Manufacturer
device_manufacturer
23
Device Name
device_name
24
Kernel Version
kernel_version
25
IP Address
ip_address
26
Public IP Address
public_ip_address
27
Wi-Fi SSID
wifi_ssid
28
Locale Country
locale_country
29
Locale Language
locale_language
30
Carrier Name
carrier_name
31
App Name
app_name
32
App Installation Date
app_installation_date
33
App Version
app_version
34
System Name
system_name
35
Centroid
centroid
36
Custom Metadata (Bundle)
metadata
37
SDK Version
sdk_version
38
Location ID
location_id
39
User ID
user_id
40
App ID
app_id
41
Local Geofence Event
local_geofence_events
42
Android SDK Version
android_sdk_version
43
Android Release Version
android_release_version
44
Build Type
build_type
45
Build Version Incremental
build_version_incremental
46
Build ID
build_id
47
AAID (Android)
aaid
48
Package Name
package_name
49
Installed Applications
installed_applications
50
Allow Mocked Locations
allow_mocked
51
OS Version
os_version
52
IDFV (iOS)
idfv
53
IDFA (iOS)
idfa
54
Source
source
55
Bundle ID
bundle_id
56
Location Listener
location_listener
57
Location Authorization Status
location_authorization_status
58
Nearby Events
nearby_events
59
App Details
app_details
60
Geofence Events
geofence_events
61
Trips Events
trips_events
62
Location Events
location_events
63
Events Listener
event_listener
64
Airplane Mode
airplane_mode
65
Discarded Flag
discarded
You’ve successfully completed the full Roam iOS SDK integration — from installing and initializing the SDK, to requesting permissions, starting location tracking, and enabling optional batch sync.
Your app is now ready to:
Continuously track user location with battery-efficient background support
Receive real-time updates through RoamDelegate
callbacks
Sync location data to Roam servers in batches, if enabled
If you’ve followed each step and are seeing location updates in your Xcode logs, your integration is working correctly.
Need help? Check out our FAQs, explore the , or contact our support team.