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 "NCRouteLayer.h"
13#import "NCGuidanceCamera.h"
14#import "NCMqttSession.h"
15
20@interface NavigineSdkExample : NSObject
21
22@property (nonatomic, strong) NCNavigineSdk *sdk;
23@property (nonatomic, strong) NCLocationManager *locationManager;
24@property (nonatomic, strong) NCNavigationManager *navigationManager;
25@property (nonatomic, strong) NCZoneManager *zoneManager;
26@property (nonatomic, strong) NCRouteManager *routeManager;
27@property (nonatomic, strong) NCAsyncRouteManager *asyncRouteManager;
28@property (nonatomic, strong) NCNotificationManager *notificationManager;
29@property (nonatomic, strong) NCMeasurementManager *measurementManager;
30@property (nonatomic, strong) NCLocationListManager *locationListManager;
31@property (nonatomic, strong) NCStorageManager *storageManager;
32@property (nonatomic, strong) NCMqttSession *mqttSession;
33@property (nonatomic, strong) NCLocationWindow *locationWindow;
34@property (nonatomic, strong) NCRouteLayer *routeLayer;
35@property (nonatomic, strong) NCGuidanceCamera *guidanceCamera;
36
37- (void)initializeSdk;
38- (void)initializeManagers;
42- (void)runExample;
43
44@end
45
46@implementation NavigineSdkExample
47
48- (instancetype)init {
49 self = [super init];
50 if (self) {
51 [self initializeSdk];
52 }
53 return self;
54}
55
59 - (void)initializeSdk {
60 @try {
61 // [objc_NavigineSdk_getInstance]
62 // Get SDK instance
63 self.sdk = [NCNavigineSdk getInstance];
64 // [objc_NavigineSdk_getInstance]
65
66 if (!self.sdk) {
67 NSLog(@"Error: failed to get NavigineSdk instance");
68 return;
69 }
70
71 // [objc_NavigineSdk_getVersion]
72 // Get SDK version
73 NSLog(@"Navigine SDK Version: %@", [NCNavigineSdk getVersion]);
74 // [objc_NavigineSdk_getVersion]
75
76 // [objc_NavigineSdk_getDeviceId]
77 // Get device ID
78 NSLog(@"Device ID: %@", [NCNavigineSdk getDeviceId]);
79 // [objc_NavigineSdk_getDeviceId]
80
81 // [objc_NavigineSdk_getRelativeTime]
82 // Get relative time
83 NSLog(@"Relative Time: %lld", [NCNavigineSdk getRelativeTime]);
84 // [objc_NavigineSdk_getRelativeTime]
85
86 // [objc_NavigineSdk_setUserHash]
87 // Set user hash (authorization token)
88 [self.sdk setUserHash:@"XXXX-XXXX-XXXX-XXXX"];
89 // [objc_NavigineSdk_setUserHash]
90
91
92 // [objc_NavigineSdk_getUserAgent]
93 NSLog(@"User-Agent: %@", [NCNavigineSdk getUserAgent]);
94 // [objc_NavigineSdk_getUserAgent]
95
96 // [objc_NavigineSdk_reset]
97 [_sdk reset];
98 NSLog(@"SDK reset to initial state");
99 // [objc_NavigineSdk_reset]
100
101 // [objc_NavigineSdk_setServer]
102 // Set server URL (optional)
103 [self.sdk setServer:@"https://custom.navigine.com"];
104 // [objc_NavigineSdk_setServer]
105
106 // Initialize managers
107 [self initializeManagers];
108
109 } @catch (NSException *exception) {
110 NSLog(@"SDK initialization error: %@", exception.reason);
111 }
112 }
113
118 // [objc_NavigineSdk_getLocationManager]
119 // Get LocationManager for working with locations
120 self.locationManager = [self.sdk getLocationManager];
121 if (self.locationManager) {
122 NSLog(@"LocationManager successfully initialized");
123 }
124 // [objc_NavigineSdk_getLocationManager]
125
126 // [objc_NavigineSdk_getNavigationManager]
127 // Get NavigationManager for navigation
128 if (self.locationManager) {
129 self.navigationManager = [self.sdk getNavigationManager:self.locationManager];
130 if (self.navigationManager) {
131 NSLog(@"NavigationManager successfully initialized");
132 }
133 }
134 // [objc_NavigineSdk_getNavigationManager]
135
136 // [objc_NavigineSdk_getZoneManager]
137 // Get ZoneManager for working with zones
138 if (self.navigationManager) {
139 self.zoneManager = [self.sdk getZoneManager:self.navigationManager];
140 if (self.zoneManager) {
141 NSLog(@"ZoneManager successfully initialized");
142 }
143 }
144 // [objc_NavigineSdk_getZoneManager]
145
146 // [objc_NavigineSdk_getRouteManager]
147 // Get RouteManager for building routes
148 if (self.locationManager && self.navigationManager) {
149 self.routeManager = [self.sdk getRouteManager:self.locationManager
150 navigationManager:self.navigationManager];
151 if (self.routeManager) {
152 NSLog(@"RouteManager successfully initialized");
153 }
154 }
155 // [objc_NavigineSdk_getRouteManager]
156
157 // [objc_NavigineSdk_getAsyncRouteManager]
158 // Get AsyncRouteManager for async route operations
159 if (self.locationManager && self.navigationManager) {
160 self.asyncRouteManager = [self.sdk getAsyncRouteManager:self.locationManager
161 navigationManager:self.navigationManager];
162 if (self.asyncRouteManager) {
163 NSLog(@"AsyncRouteManager successfully initialized");
164 }
165 }
166 // [objc_NavigineSdk_getAsyncRouteManager]
167
168 // [objc_NavigineSdk_getNotificationManager]
169 // Get NotificationManager for notifications
170 if (self.locationManager) {
171 self.notificationManager = [self.sdk getNotificationManager:self.locationManager];
172 if (self.notificationManager) {
173 NSLog(@"NotificationManager successfully initialized");
174 }
175 }
176 // [objc_NavigineSdk_getNotificationManager]
177
178 // [objc_NavigineSdk_getMeasurementManager]
179 // Get MeasurementManager for measurements
180 if (self.locationManager) {
181 self.measurementManager = [self.sdk getMeasurementManager:self.locationManager];
182 if (self.measurementManager) {
183 NSLog(@"MeasurementManager successfully initialized");
184 }
185 }
186 // [objc_NavigineSdk_getMeasurementManager]
187
188 // [objc_NavigineSdk_getLocationListManager]
189 // Get LocationListManager for location list operations
190 self.locationListManager = [self.sdk getLocationListManager];
191 if (self.locationListManager) {
192 NSLog(@"LocationListManager successfully initialized");
193 }
194 // [objc_NavigineSdk_getLocationListManager]
195
196 // [objc_NavigineSdk_getStorageManager]
197 // Get StorageManager for working with storages
198 self.storageManager = [self.sdk getStorageManager];
199 if (self.storageManager) {
200 NSLog(@"StorageManager successfully initialized");
201 }
202 // [objc_NavigineSdk_getStorageManager]
203
204 // [objc_NavigineSdk_getRouteLayer]
205 // Create RouteLayer for building and drawing routes on the map
206 if (self.locationWindow) {
207 self.routeLayer = [self.sdk getRouteLayer:self.locationWindow];
208 if (self.routeLayer) {
209 NSLog(@"RouteLayer successfully initialized");
210 }
211 }
212 // [objc_NavigineSdk_getRouteLayer]
213
214 // [objc_NavigineSdk_getGuidanceCamera]
215 if (self.locationWindow && self.routeLayer) {
216 self.guidanceCamera = [self.sdk getGuidanceCamera:self.locationWindow routeLayer:self.routeLayer];
217 // [objc_GuidanceCamera_setMode]
218 [self.guidanceCamera setMode:NCGuidanceCameraModeFOLLOWING];
219 // [objc_GuidanceCamera_setMode]
220 // [objc_GuidanceCamera_set2DMode]
221 [self.guidanceCamera set2DMode:NO];
222 // [objc_GuidanceCamera_set2DMode]
223 // [objc_GuidanceCamera_mode]
224 NSLog(@"Guidance mode: %ld", (long)[self.guidanceCamera mode]);
225 // [objc_GuidanceCamera_mode]
226 // [objc_GuidanceCamera_instruction]
228 if (next) {
229 NSLog(@"Next instruction: %@ %.0f m", next.title, next.distance);
230 }
231 // [objc_GuidanceCamera_instruction]
232 }
233 // [objc_NavigineSdk_getGuidanceCamera]
234
235 // [objc_NavigineSdk_getRouteSimulator]
236 if (self.locationWindow) {
237 NCRouteSimulator *routeSimulator = [self.sdk getRouteSimulator:self.locationWindow];
238 // [objc_RouteSimulator_setGeometry]
239 NCLocationPolyline *walk = [[NCLocationPolyline alloc] initWithPoints:@[
240 [[NCGlobalPoint alloc] initWithLatitude:55.751 longitude:37.618],
241 [[NCGlobalPoint alloc] initWithLatitude:55.752 longitude:37.618],
242 ] sublocationId:nil];
244 // [objc_RouteSimulator_setGeometry]
245 // [objc_RouteSimulator_setSpeed]
247 // [objc_RouteSimulator_setSpeed]
248 // [objc_RouteSimulator_start]
249 BOOL started = [routeSimulator start];
250 NSLog(@"Route walk started: %@", started ? @"YES" : @"NO");
251 // [objc_RouteSimulator_start]
252 // [objc_RouteSimulator_sample]
254 if (sample) {
255 NSLog(@"Walk advance: %f m", sample.advance);
256 }
257 // [objc_RouteSimulator_sample]
258 }
259 // [objc_NavigineSdk_getRouteSimulator]
260
261 // [objc_NavigineSdk_getMqttSession]
262 // Get MqttSession for publishing position data via MQTT
263 if (self.navigationManager) {
264 self.mqttSession = [self.sdk getMqttSession:self.navigationManager];
265 if (self.mqttSession) {
266 NSLog(@"MqttSession successfully initialized");
267 }
268 }
269 // [objc_NavigineSdk_getMqttSession]
270 }
271
275 - (void)printSdkInfo {
276 NSLog(@"=== Navigine SDK Information ===");
277 NSLog(@"SDK Version: %@", [NCNavigineSdk getVersion]);
278 NSLog(@"Device ID: %@", [NCNavigineSdk getDeviceId]);
279 NSLog(@"Relative Time: %lld", [NCNavigineSdk getRelativeTime]);
280 NSLog(@"LocationManager: %@", self.locationManager ? @"available" : @"unavailable");
281 NSLog(@"NavigationManager: %@", self.navigationManager ? @"available" : @"unavailable");
282 NSLog(@"ZoneManager: %@", self.zoneManager ? @"available" : @"unavailable");
283 NSLog(@"RouteManager: %@", self.routeManager ? @"available" : @"unavailable");
284 NSLog(@"AsyncRouteManager: %@", self.asyncRouteManager ? @"available" : @"unavailable");
285 NSLog(@"NotificationManager: %@", self.notificationManager ? @"available" : @"unavailable");
286 NSLog(@"MeasurementManager: %@", self.measurementManager ? @"available" : @"unavailable");
287 NSLog(@"LocationListManager: %@", self.locationListManager ? @"available" : @"unavailable");
288 NSLog(@"StorageManager: %@", self.storageManager ? @"available" : @"unavailable");
289 NSLog(@"MqttSession: %@", self.mqttSession ? @"available" : @"unavailable");
290 }
291
296 NSLog(@"=== Manager Usage Demonstration ===");
297
298 // LocationManager usage example
299 if (self.locationManager) {
300 NSLog(@"LocationManager ready for location operations");
301 // Add code here for loading locations, working with them, etc.
302 }
303
304 // NavigationManager usage example
305 if (self.navigationManager) {
306 NSLog(@"NavigationManager ready for positioning");
307 // Add code here for getting position, setting up listeners, etc.
308 }
309
310 // ZoneManager usage example
311 if (self.zoneManager) {
312 NSLog(@"ZoneManager ready for zone operations");
313 // Add code here for setting up zones, handling enter/exit events, etc.
314 }
315
316 // RouteManager usage example
317 if (self.routeManager) {
318 NSLog(@"RouteManager ready for route building");
319 // Add code here for building routes, setting destination points, etc.
320 }
321
322 // AsyncRouteManager usage example
323 if (self.asyncRouteManager) {
324 NSLog(@"AsyncRouteManager ready for async route operations");
325 // Add code here for creating routing sessions, etc.
326 }
327
328 // NotificationManager usage example
329 if (self.notificationManager) {
330 NSLog(@"NotificationManager ready for notifications");
331 // Add code here for setting up beacon notifications, etc.
332 }
333
334 // MeasurementManager usage example
335 if (self.measurementManager) {
336 NSLog(@"MeasurementManager ready for measurements");
337 // Add code here for managing measurement generators, etc.
338 }
339
340 // LocationListManager usage example
341 if (self.locationListManager) {
342 NSLog(@"LocationListManager ready for location list operations");
343 // Add code here for getting available locations list, etc.
344 }
345
346 // StorageManager usage example
347 if (self.storageManager) {
348 NSLog(@"StorageManager ready for storage operations");
349 // Add code here for creating storages, managing data, etc.
350 }
351
352 // MqttSession usage example
353 if (self.mqttSession) {
354 NSLog(@"MqttSession ready for publishing position data via MQTT");
355 // Add code here for connecting to MQTT broker, publishing positions, etc.
356 }
357 }
358
362 - (void)demonstrateObjectiveCFeatures {
363 NSLog(@"=== Objective-C Features Demonstration ===");
364
365 // Using blocks for async operations
366 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
367 // Async operation
368 dispatch_async(dispatch_get_main_queue(), ^{
369 NSLog(@"Async operation completed");
370 });
371 });
372
373 // Using KVO (Key-Value Observing) - example
374 [self addObserver:self forKeyPath:@"locationManager" options:NSKeyValueObservingOptionNew context:nil];
375
376 // Using categories (if they were defined)
377 // [self.sdk performCustomOperation];
378
379 // Using selectors
380 SEL selector = @selector(printSdkInfo);
381 if ([self respondsToSelector:selector]) {
382 [self performSelector:selector];
383 }
384 }
385
389 - (void)observeValueForKeyPath:(NSString *)keyPath
390 ofObject:(id)object
391 change:(NSDictionary<NSKeyValueChangeKey,id> *)change
392 context:(void *)context {
393 if ([keyPath isEqualToString:@"locationManager"]) {
394 NSLog(@"LocationManager changed");
395 }
396 }
397
401 - (void)runExample {
402 [self printSdkInfo];
403 [self demonstrateManagersUsage];
404 [self demonstrateObjectiveCFeatures];
405 }
406
407- (void)dealloc {
408 [self removeObserver:self forKeyPath:@"locationManager"];
409}
410
411@end
412
416int main(int argc, const char * argv[]) {
417 @autoreleasepool {
418 NavigineSdkExample *example = [[NavigineSdkExample alloc] init];
419 [example runExample];
420 }
421 return 0;
422}