Loading...
Searching...
No Matches
NavigineSdkExample.m
Go to the documentation of this file.
1#import <Foundation/Foundation.h>
2#import "NCNavigineSdk.h"
5#import "NCZoneManager.h"
6#import "NCRouteManager.h"
11#import "NCLocationWindow.h"
12#import "NCMqttSession.h"
13
18@interface NavigineSdkExample : NSObject
19
20@property (nonatomic, strong) NCNavigineSdk *sdk;
21@property (nonatomic, strong) NCLocationManager *locationManager;
22@property (nonatomic, strong) NCNavigationManager *navigationManager;
23@property (nonatomic, strong) NCZoneManager *zoneManager;
24@property (nonatomic, strong) NCRouteManager *routeManager;
25@property (nonatomic, strong) NCAsyncRouteManager *asyncRouteManager;
26@property (nonatomic, strong) NCNotificationManager *notificationManager;
27@property (nonatomic, strong) NCMeasurementManager *measurementManager;
28@property (nonatomic, strong) NCLocationListManager *locationListManager;
29@property (nonatomic, strong) NCStorageManager *storageManager;
30@property (nonatomic, strong) NCMqttSession *mqttSession;
31
32- (void)initializeSdk;
33- (void)initializeManagers;
37- (void)runExample;
38
39@end
40
41@implementation NavigineSdkExample
42
43- (instancetype)init {
44 self = [super init];
45 if (self) {
46 [self initializeSdk];
47 }
48 return self;
49}
50
54 - (void)initializeSdk {
55 @try {
56 // [objc_NavigineSdk_getInstance]
57 // Get SDK instance
58 self.sdk = [NCNavigineSdk getInstance];
59 // [objc_NavigineSdk_getInstance]
60
61 if (!self.sdk) {
62 NSLog(@"Error: failed to get NavigineSdk instance");
63 return;
64 }
65
66 // [objc_NavigineSdk_getVersion]
67 // Get SDK version
68 NSLog(@"Navigine SDK Version: %@", [NCNavigineSdk getVersion]);
69 // [objc_NavigineSdk_getVersion]
70
71 // [objc_NavigineSdk_getDeviceId]
72 // Get device ID
73 NSLog(@"Device ID: %@", [NCNavigineSdk getDeviceId]);
74 // [objc_NavigineSdk_getDeviceId]
75
76 // [objc_NavigineSdk_getRelativeTime]
77 // Get relative time
78 NSLog(@"Relative Time: %lld", [NCNavigineSdk getRelativeTime]);
79 // [objc_NavigineSdk_getRelativeTime]
80
81 // [objc_NavigineSdk_setUserHash]
82 // Set user hash (authorization token)
83 [self.sdk setUserHash:@"XXXX-XXXX-XXXX-XXXX"];
84 // [objc_NavigineSdk_setUserHash]
85
86
87 // [objc_NavigineSdk_getUserAgent]
88 NSLog(@"User-Agent: %@", [NCNavigineSdk getUserAgent]);
89 // [objc_NavigineSdk_getUserAgent]
90
91 // [objc_NavigineSdk_reset]
92 [_sdk reset];
93 NSLog(@"SDK reset to initial state");
94 // [objc_NavigineSdk_reset]
95
96 // [objc_NavigineSdk_setServer]
97 // Set server URL (optional)
98 [self.sdk setServer:@"https://custom.navigine.com"];
99 // [objc_NavigineSdk_setServer]
100
101 // Initialize managers
102 [self initializeManagers];
103
104 } @catch (NSException *exception) {
105 NSLog(@"SDK initialization error: %@", exception.reason);
106 }
107 }
108
113 // [objc_NavigineSdk_getLocationManager]
114 // Get LocationManager for working with locations
115 self.locationManager = [self.sdk getLocationManager];
116 if (self.locationManager) {
117 NSLog(@"LocationManager successfully initialized");
118 }
119 // [objc_NavigineSdk_getLocationManager]
120
121 // [objc_NavigineSdk_getNavigationManager]
122 // Get NavigationManager for navigation
123 if (self.locationManager) {
124 self.navigationManager = [self.sdk getNavigationManager:self.locationManager];
125 if (self.navigationManager) {
126 NSLog(@"NavigationManager successfully initialized");
127 }
128 }
129 // [objc_NavigineSdk_getNavigationManager]
130
131 // [objc_NavigineSdk_getZoneManager]
132 // Get ZoneManager for working with zones
133 if (self.navigationManager) {
134 self.zoneManager = [self.sdk getZoneManager:self.navigationManager];
135 if (self.zoneManager) {
136 NSLog(@"ZoneManager successfully initialized");
137 }
138 }
139 // [objc_NavigineSdk_getZoneManager]
140
141 // [objc_NavigineSdk_getRouteManager]
142 // Get RouteManager for building routes
143 if (self.locationManager && self.navigationManager) {
144 self.routeManager = [self.sdk getRouteManager:self.locationManager
145 navigationManager:self.navigationManager];
146 if (self.routeManager) {
147 NSLog(@"RouteManager successfully initialized");
148 }
149 }
150 // [objc_NavigineSdk_getRouteManager]
151
152 // [objc_NavigineSdk_getAsyncRouteManager]
153 // Get AsyncRouteManager for async route operations
154 if (self.locationManager && self.navigationManager) {
155 self.asyncRouteManager = [self.sdk getAsyncRouteManager:self.locationManager
156 navigationManager:self.navigationManager];
157 if (self.asyncRouteManager) {
158 NSLog(@"AsyncRouteManager successfully initialized");
159 }
160 }
161 // [objc_NavigineSdk_getAsyncRouteManager]
162
163 // [objc_NavigineSdk_getNotificationManager]
164 // Get NotificationManager for notifications
165 if (self.locationManager) {
166 self.notificationManager = [self.sdk getNotificationManager:self.locationManager];
167 if (self.notificationManager) {
168 NSLog(@"NotificationManager successfully initialized");
169 }
170 }
171 // [objc_NavigineSdk_getNotificationManager]
172
173 // [objc_NavigineSdk_getMeasurementManager]
174 // Get MeasurementManager for measurements
175 if (self.locationManager) {
176 self.measurementManager = [self.sdk getMeasurementManager:self.locationManager];
177 if (self.measurementManager) {
178 NSLog(@"MeasurementManager successfully initialized");
179 }
180 }
181 // [objc_NavigineSdk_getMeasurementManager]
182
183 // [objc_NavigineSdk_getLocationListManager]
184 // Get LocationListManager for location list operations
185 self.locationListManager = [self.sdk getLocationListManager];
186 if (self.locationListManager) {
187 NSLog(@"LocationListManager successfully initialized");
188 }
189 // [objc_NavigineSdk_getLocationListManager]
190
191 // [objc_NavigineSdk_getStorageManager]
192 // Get StorageManager for working with storages
193 self.storageManager = [self.sdk getStorageManager];
194 if (self.storageManager) {
195 NSLog(@"StorageManager successfully initialized");
196 }
197 // [objc_NavigineSdk_getStorageManager]
198
199 // [objc_NavigineSdk_getMqttSession]
200 // Get MqttSession for publishing position data via MQTT
201 if (self.navigationManager) {
202 self.mqttSession = [self.sdk getMqttSession:self.navigationManager];
203 if (self.mqttSession) {
204 NSLog(@"MqttSession successfully initialized");
205 }
206 }
207 // [objc_NavigineSdk_getMqttSession]
208 }
209
213 - (void)printSdkInfo {
214 NSLog(@"=== Navigine SDK Information ===");
215 NSLog(@"SDK Version: %@", [NCNavigineSdk getVersion]);
216 NSLog(@"Device ID: %@", [NCNavigineSdk getDeviceId]);
217 NSLog(@"Relative Time: %lld", [NCNavigineSdk getRelativeTime]);
218 NSLog(@"LocationManager: %@", self.locationManager ? @"available" : @"unavailable");
219 NSLog(@"NavigationManager: %@", self.navigationManager ? @"available" : @"unavailable");
220 NSLog(@"ZoneManager: %@", self.zoneManager ? @"available" : @"unavailable");
221 NSLog(@"RouteManager: %@", self.routeManager ? @"available" : @"unavailable");
222 NSLog(@"AsyncRouteManager: %@", self.asyncRouteManager ? @"available" : @"unavailable");
223 NSLog(@"NotificationManager: %@", self.notificationManager ? @"available" : @"unavailable");
224 NSLog(@"MeasurementManager: %@", self.measurementManager ? @"available" : @"unavailable");
225 NSLog(@"LocationListManager: %@", self.locationListManager ? @"available" : @"unavailable");
226 NSLog(@"StorageManager: %@", self.storageManager ? @"available" : @"unavailable");
227 NSLog(@"MqttSession: %@", self.mqttSession ? @"available" : @"unavailable");
228 }
229
234 NSLog(@"=== Manager Usage Demonstration ===");
235
236 // LocationManager usage example
237 if (self.locationManager) {
238 NSLog(@"LocationManager ready for location operations");
239 // Add code here for loading locations, working with them, etc.
240 }
241
242 // NavigationManager usage example
243 if (self.navigationManager) {
244 NSLog(@"NavigationManager ready for positioning");
245 // Add code here for getting position, setting up listeners, etc.
246 }
247
248 // ZoneManager usage example
249 if (self.zoneManager) {
250 NSLog(@"ZoneManager ready for zone operations");
251 // Add code here for setting up zones, handling enter/exit events, etc.
252 }
253
254 // RouteManager usage example
255 if (self.routeManager) {
256 NSLog(@"RouteManager ready for route building");
257 // Add code here for building routes, setting destination points, etc.
258 }
259
260 // AsyncRouteManager usage example
261 if (self.asyncRouteManager) {
262 NSLog(@"AsyncRouteManager ready for async route operations");
263 // Add code here for creating routing sessions, etc.
264 }
265
266 // NotificationManager usage example
267 if (self.notificationManager) {
268 NSLog(@"NotificationManager ready for notifications");
269 // Add code here for setting up beacon notifications, etc.
270 }
271
272 // MeasurementManager usage example
273 if (self.measurementManager) {
274 NSLog(@"MeasurementManager ready for measurements");
275 // Add code here for managing measurement generators, etc.
276 }
277
278 // LocationListManager usage example
279 if (self.locationListManager) {
280 NSLog(@"LocationListManager ready for location list operations");
281 // Add code here for getting available locations list, etc.
282 }
283
284 // StorageManager usage example
285 if (self.storageManager) {
286 NSLog(@"StorageManager ready for storage operations");
287 // Add code here for creating storages, managing data, etc.
288 }
289
290 // MqttSession usage example
291 if (self.mqttSession) {
292 NSLog(@"MqttSession ready for publishing position data via MQTT");
293 // Add code here for connecting to MQTT broker, publishing positions, etc.
294 }
295 }
296
300 - (void)demonstrateObjectiveCFeatures {
301 NSLog(@"=== Objective-C Features Demonstration ===");
302
303 // Using blocks for async operations
304 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
305 // Async operation
306 dispatch_async(dispatch_get_main_queue(), ^{
307 NSLog(@"Async operation completed");
308 });
309 });
310
311 // Using KVO (Key-Value Observing) - example
312 [self addObserver:self forKeyPath:@"locationManager" options:NSKeyValueObservingOptionNew context:nil];
313
314 // Using categories (if they were defined)
315 // [self.sdk performCustomOperation];
316
317 // Using selectors
318 SEL selector = @selector(printSdkInfo);
319 if ([self respondsToSelector:selector]) {
320 [self performSelector:selector];
321 }
322 }
323
327 - (void)observeValueForKeyPath:(NSString *)keyPath
328 ofObject:(id)object
329 change:(NSDictionary<NSKeyValueChangeKey,id> *)change
330 context:(void *)context {
331 if ([keyPath isEqualToString:@"locationManager"]) {
332 NSLog(@"LocationManager changed");
333 }
334 }
335
339 - (void)runExample {
340 [self printSdkInfo];
341 [self demonstrateManagersUsage];
342 [self demonstrateObjectiveCFeatures];
343 }
344
345- (void)dealloc {
346 [self removeObserver:self forKeyPath:@"locationManager"];
347}
348
349@end
350
354int main(int argc, const char * argv[]) {
355 @autoreleasepool {
356 NavigineSdkExample *example = [[NavigineSdkExample alloc] init];
357 [example runExample];
358 }
359 return 0;
360}