First, install the Radar SDK using CocoaPods or Swift Package Manager. See the installation guide for detailed instructions.For CocoaPods, add to your Podfile:
pod 'RadarSDK', '~> 3.27.0'
Then run:
pod install
2
Configure Info.plist
Add location permission descriptions to your Info.plist:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key><string>We use your location to provide location-based features.</string><key>NSLocationWhenInUseUsageDescription</key><string>We use your location while you're using the app.</string>
3
Initialize the SDK
In your AppDelegate.swift, initialize Radar with your publishable key:
Implement RadarDelegate to receive events and location updates:
import RadarSDKclass MyRadarDelegate: NSObject, RadarDelegate { func didReceiveEvents(_ events: [RadarEvent], user: RadarUser?) { print("📬 Received \(events.count) event(s)") for event in events { switch event.type { case .userEnteredGeofence: if let geofence = event.geofence { print("🎯 Entered geofence: \(geofence.description)") } case .userExitedGeofence: if let geofence = event.geofence { print("👋 Exited geofence: \(geofence.description)") } case .userEnteredPlace: if let place = event.place { print("🏪 Entered place: \(place.name)") } default: print("📍 Event: \(event.type)") } } } func didUpdateLocation(_ location: CLLocation, user: RadarUser) { print("📍 Location updated: \(location.coordinate)") print("👤 User state updated") // Check if user is in any geofences if let geofences = user.geofences, !geofences.isEmpty { print(" In \(geofences.count) geofence(s)") } // Check if user is at a place if let place = user.place { print(" At: \(place.name)") } } func didUpdateClientLocation(_ location: CLLocation, stopped: Bool, source: RadarLocationSource) { print("📱 Client location: \(location.coordinate) (stopped: \(stopped))") } func didFail(status: RadarStatus) { print("❌ Radar error: \(Radar.string(for: status))") } func didLog(message: String) { print("🔍 Radar log: \(message)") }}
// Set user ID (e.g., your internal user ID)Radar.setUserId("user_12345")// Set user descriptionRadar.setDescription("Premium User")// Set custom metadataRadar.setMetadata([ "plan": "premium", "signupDate": "2024-01-15"])
If you don’t set a user ID, Radar automatically identifies users by device ID (IDFV).
Make sure you’ve added the required NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription keys to your Info.plist.On iOS 13.4+, you must request “When In Use” permission before requesting “Always” permission.
Background tracking not working
Verify that:
You’ve enabled the Location updates background mode in Signing & Capabilities
The user granted “Always” location permission (not just “When In Use”)
You called Radar.startTracking() with valid tracking options
Events not received
Make sure:
You’ve set a delegate with Radar.setDelegate()
You’re keeping a strong reference to your delegate object