The RadarDelegate protocol provides client-side delivery of location updates, events, and debug logs. Implementing this delegate allows you to respond to location changes and Radar events in real-time within your app.
Called when events are generated by Radar, such as geofence entries/exits, place visits, or trip updates.
func didReceiveEvents(_ events: [RadarEvent], user: RadarUser?) { for event in events { switch event.type { case .userEnteredGeofence: if let geofence = event.geofence { print("Entered geofence: \(geofence.tag ?? "unknown")") } case .userExitedGeofence: if let geofence = event.geofence { print("Exited geofence: \(geofence.tag ?? "unknown")") } case .userEnteredPlace: if let place = event.place { print("Entered place: \(place.name)") } case .userArrivedAtTripDestination: print("User arrived at trip destination") // Update UI, send notification, etc. case .userStoppedTrip: print("User stopped trip") // Complete delivery workflow default: print("Received event: \(event.type)") } } // Access updated user state if let user = user { print("User location: \(user.location?.coordinate ?? CLLocationCoordinate2D())") print("User geofences: \(user.geofences?.count ?? 0)") }}
Parameters:
events: Array of RadarEvent objects representing the events that were generated
user: The updated RadarUser object, or nil if anonymous tracking is enabled
Use this method to update your UI, trigger notifications, or update your app’s state based on location events.
Called when the user’s location is updated and successfully synced to the server.
func didUpdateLocation(_ location: CLLocation, user: RadarUser) { print("Location updated: \(location.coordinate.latitude), \(location.coordinate.longitude)") print("Accuracy: \(location.horizontalAccuracy)m") // Access user state if let place = user.place { print("At place: \(place.name)") } if let country = user.country { print("In country: \(country.name)") } // Update map or UI with new location updateMapWithLocation(location)}
Parameters:
location: The CLLocation object representing the user’s current location
user: The updated RadarUser object with current context and state
This method is only called for location updates that are successfully synced to the server. Use didUpdateClientLocation if you need all location updates.
func didFail(status: RadarStatus) { switch status { case .errorPublishableKey: print("Error: SDK not initialized") case .errorPermissions: print("Error: Location permissions not granted") // Show permission request UI case .errorLocation: print("Error: Location services error or timeout") case .errorNetwork: print("Error: Network error or timeout") case .errorUnauthorized: print("Error: Invalid API key") case .errorRateLimit: print("Error: Rate limit exceeded") default: print("Error: \(status)") }}
Parameters:
status: The RadarStatus error code indicating what went wrong
Called when the SDK generates debug log messages. Useful for debugging and troubleshooting.
func didLog(message: String) { print("[Radar] \(message)") // You can also log to your analytics service // Analytics.log("radar_sdk", message: message)}
Parameters:
message: The debug log message string
Enable log messages by setting the log level: Radar.setLogLevel(.debug)