5 * NavigineSDK usage example for Swift
6 * Demonstrates SDK initialization and access to various managers
8class NavigineSdkExample {
10 private var sdk: NCNavigineSdk?
11 private var locationManager: NCLocationManager?
12 private var navigationManager: NCNavigationManager?
13 private var zoneManager: NCZoneManager?
14 private var routeManager: NCRouteManager?
15 private var asyncRouteManager: NCAsyncRouteManager?
16 private var notificationManager: NCNotificationManager?
17 private var measurementManager: NCMeasurementManager?
18 private var locationListManager: NCLocationListManager?
19 private var storageManager: NCStorageManager?
26 * SDK initialization and basic parameter setup
28 private func initializeSdk() {
30 // [swift_NavigineSdk_getInstance]
32 sdk = NCNavigineSdk.getInstance()
33 // [swift_NavigineSdk_getInstance]
35 guard let sdk = sdk else {
36 print("Error: failed to get NavigineSdk instance")
40 // [swift_NavigineSdk_getVersion]
42 print("Navigine SDK Version: \(NCNavigineSdk.getVersion())")
43 // [swift_NavigineSdk_getVersion]
45 // [swift_NavigineSdk_getDeviceId]
47 print("Device ID: \(NCNavigineSdk.getDeviceId())")
48 // [swift_NavigineSdk_getDeviceId]
50 // [swift_NavigineSdk_getRelativeTime]
52 print("Relative Time: \(NCNavigineSdk.getRelativeTime())")
53 // [swift_NavigineSdk_getRelativeTime]
55 // [swift_NavigineSdk_setUserHash]
56 // Set user hash (authorization token)
57 sdk.setUserHash("XXXX-XXXX-XXXX-XXXX")
58 // [swift_NavigineSdk_setUserHash]
60 // [swift_NavigineSdk_setServer]
61 // Set server URL (optional)
62 sdk.setServer("https://custom.navigine.com")
63 // [swift_NavigineSdk_setServer]
65 // Initialize managers
69 print("SDK initialization error: \(error)")
74 * Initialize all SDK managers
76 private func initializeManagers() {
77 guard let sdk = sdk else { return }
79 // [swift_NavigineSdk_getLocationManager]
80 // Get LocationManager for working with locations
81 locationManager = sdk.getLocationManager()
82 if locationManager != nil {
83 print("LocationManager successfully initialized")
85 // [swift_NavigineSdk_getLocationManager]
87 // [swift_NavigineSdk_getNavigationManager]
88 // Get NavigationManager for navigation
89 if let locationManager = locationManager {
90 navigationManager = sdk.getNavigationManager(locationManager)
91 if navigationManager != nil {
92 print("NavigationManager successfully initialized")
95 // [swift_NavigineSdk_getNavigationManager]
97 // [swift_NavigineSdk_getZoneManager]
98 // Get ZoneManager for working with zones
99 if let navigationManager = navigationManager {
100 zoneManager = sdk.getZoneManager(navigationManager)
101 if zoneManager != nil {
102 print("ZoneManager successfully initialized")
105 // [swift_NavigineSdk_getZoneManager]
107 // [swift_NavigineSdk_getRouteManager]
108 // Get RouteManager for building routes
109 if let locationManager = locationManager,
110 let navigationManager = navigationManager {
111 routeManager = sdk.getRouteManager(locationManager, navigationManager: navigationManager)
112 if routeManager != nil {
113 print("RouteManager successfully initialized")
116 // [swift_NavigineSdk_getRouteManager]
118 // [swift_NavigineSdk_getAsyncRouteManager]
119 // Get AsyncRouteManager for async route operations
120 if let locationManager = locationManager,
121 let navigationManager = navigationManager {
122 asyncRouteManager = sdk.getAsyncRouteManager(locationManager, navigationManager: navigationManager)
123 if asyncRouteManager != nil {
124 print("AsyncRouteManager successfully initialized")
127 // [swift_NavigineSdk_getAsyncRouteManager]
129 // [swift_NavigineSdk_getNotificationManager]
130 // Get NotificationManager for notifications
131 if let locationManager = locationManager {
132 notificationManager = sdk.getNotificationManager(locationManager)
133 if notificationManager != nil {
134 print("NotificationManager successfully initialized")
137 // [swift_NavigineSdk_getNotificationManager]
139 // [swift_NavigineSdk_getMeasurementManager]
140 // Get MeasurementManager for measurements
141 if let locationManager = locationManager {
142 measurementManager = sdk.getMeasurementManager(locationManager)
143 if measurementManager != nil {
144 print("MeasurementManager successfully initialized")
147 // [swift_NavigineSdk_getMeasurementManager]
149 // [swift_NavigineSdk_getLocationListManager]
150 // Get LocationListManager for location list operations
151 locationListManager = sdk.getLocationListManager()
152 if locationListManager != nil {
153 print("LocationListManager successfully initialized")
155 // [swift_NavigineSdk_getLocationListManager]
157 // [swift_NavigineSdk_getStorageManager]
158 // Get StorageManager for working with storages
159 storageManager = sdk.getStorageManager()
160 if storageManager != nil {
161 print("StorageManager successfully initialized")
163 // [swift_NavigineSdk_getStorageManager]
167 * Get information about current SDK state
169 func printSdkInfo() {
170 print("=== Navigine SDK Information ===")
171 print("SDK Version: \(NCNavigineSdk.getVersion())")
172 print("Device ID: \(NCNavigineSdk.getDeviceId())")
173 print("Relative Time: \(NCNavigineSdk.getRelativeTime())")
174 print("LocationManager: \(locationManager != nil ? "available" : "unavailable")")
175 print("NavigationManager: \(navigationManager != nil ? "available" : "unavailable")")
176 print("ZoneManager: \(zoneManager != nil ? "available" : "unavailable")")
177 print("RouteManager: \(routeManager != nil ? "available" : "unavailable")")
178 print("AsyncRouteManager: \(asyncRouteManager != nil ? "available" : "unavailable")")
179 print("NotificationManager: \(notificationManager != nil ? "available" : "unavailable")")
180 print("MeasurementManager: \(measurementManager != nil ? "available" : "unavailable")")
181 print("LocationListManager: \(locationListManager != nil ? "available" : "unavailable")")
182 print("StorageManager: \(storageManager != nil ? "available" : "unavailable")")
186 * Demonstrate usage of all managers
188 func demonstrateManagersUsage() {
189 print("=== Manager Usage Demonstration ===")
191 // LocationManager usage example
192 if let locationManager = locationManager {
193 print("LocationManager ready for location operations")
194 // Add code here for loading locations, working with them, etc.
197 // NavigationManager usage example
198 if let navigationManager = navigationManager {
199 print("NavigationManager ready for positioning")
200 // Add code here for getting position, setting up listeners, etc.
203 // ZoneManager usage example
204 if let zoneManager = zoneManager {
205 print("ZoneManager ready for zone operations")
206 // Add code here for setting up zones, handling enter/exit events, etc.
209 // RouteManager usage example
210 if let routeManager = routeManager {
211 print("RouteManager ready for route building")
212 // Add code here for building routes, setting destination points, etc.
215 // AsyncRouteManager usage example
216 if let asyncRouteManager = asyncRouteManager {
217 print("AsyncRouteManager ready for async route operations")
218 // Add code here for creating routing sessions, etc.
221 // NotificationManager usage example
222 if let notificationManager = notificationManager {
223 print("NotificationManager ready for notifications")
224 // Add code here for setting up beacon notifications, etc.
227 // MeasurementManager usage example
228 if let measurementManager = measurementManager {
229 print("MeasurementManager ready for measurements")
230 // Add code here for managing measurement generators, etc.
233 // LocationListManager usage example
234 if let locationListManager = locationListManager {
235 print("LocationListManager ready for location list operations")
236 // Add code here for getting available locations list, etc.
239 // StorageManager usage example
240 if let storageManager = storageManager {
241 print("StorageManager ready for storage operations")
242 // Add code here for creating storages, managing data, etc.
247 * Demonstrate Swift features usage
249 func demonstrateSwiftFeatures() {
250 print("=== Swift Features Demonstration ===")
252 // Using guard let for safe optional unwrapping
253 guard let sdk = sdk else {
254 print("SDK unavailable")
258 // Using defer for cleanup code execution
260 print("Swift features demonstration completed")
263 // Using map for data transformation
265 "version": NCNavigineSdk.getVersion(),
266 "deviceId": NCNavigineSdk.getDeviceId(),
267 "relativeTime": NCNavigineSdk.getRelativeTime()
270 let infoStrings = sdkInfo.map { key, value in
273 print("SDK Information: \(infoStrings.joined(separator: ", "))")
275 // Using compactMap for nil filtering
288 let availableManagers = managers.compactMap { $0 }
289 print("Available managers: \(availableManagers.count)")
291 // Using async/await (if supported)
293 await performAsyncOperation()
301 private func performAsyncOperation() async {
302 // Simulate async operation
303 try? await Task.sleep(nanoseconds: 1_000_000_000) // 1 second
304 print("Async operation completed")
308 * Demonstrate property wrappers usage
310 func demonstratePropertyWrappers() {
311 print("=== Property Wrappers Demonstration ===")
313 // Example of @Published usage (if this was an ObservableObject)
314 // @Published var sdkVersion = NCNavigineSdk.getVersion()
316 // Example of @State usage (for SwiftUI)
317 // @State private var isInitialized = false
319 print("Property wrappers demonstrated")
323 * Main method for demonstration
327 demonstrateManagersUsage()
328 demonstrateSwiftFeatures()
329 demonstratePropertyWrappers()
334 * Extension for additional functionality
336extension NavigineSdkExample {
339 * Get status of all managers
341 func getManagersStatus() -> [String: Bool] {
343 "LocationManager": locationManager != nil,
344 "NavigationManager": navigationManager != nil,
345 "ZoneManager": zoneManager != nil,
346 "RouteManager": routeManager != nil,
347 "AsyncRouteManager": asyncRouteManager != nil,
348 "NotificationManager": notificationManager != nil,
349 "MeasurementManager": measurementManager != nil,
350 "LocationListManager": locationListManager != nil
355 * Check if SDK is ready for work
357 func isSdkReady() -> Bool {
358 return sdk != nil && locationManager != nil
363 * Function to run the example
366 let example = NavigineSdkExample()