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 // [objc_NavigineSdk_setServer]
87 // Set server URL (optional)
88 [self.sdk setServer:@"https://custom.navigine.com"];
89 // [objc_NavigineSdk_setServer]
90
91 // Initialize managers
92 [self initializeManagers];
93
94 } @catch (NSException *exception) {
95 NSLog(@"SDK initialization error: %@", exception.reason);
96 }
97 }
98
103 // [objc_NavigineSdk_getLocationManager]
104 // Get LocationManager for working with locations
105 self.locationManager = [self.sdk getLocationManager];
106 if (self.locationManager) {
107 NSLog(@"LocationManager successfully initialized");
108 }
109 // [objc_NavigineSdk_getLocationManager]
110
111 // [objc_NavigineSdk_getNavigationManager]
112 // Get NavigationManager for navigation
113 if (self.locationManager) {
114 self.navigationManager = [self.sdk getNavigationManager:self.locationManager];
115 if (self.navigationManager) {
116 NSLog(@"NavigationManager successfully initialized");
117 }
118 }
119 // [objc_NavigineSdk_getNavigationManager]
120
121 // [objc_NavigineSdk_getZoneManager]
122 // Get ZoneManager for working with zones
123 if (self.navigationManager) {
124 self.zoneManager = [self.sdk getZoneManager:self.navigationManager];
125 if (self.zoneManager) {
126 NSLog(@"ZoneManager successfully initialized");
127 }
128 }
129 // [objc_NavigineSdk_getZoneManager]
130
131 // [objc_NavigineSdk_getRouteManager]
132 // Get RouteManager for building routes
133 if (self.locationManager && self.navigationManager) {
134 self.routeManager = [self.sdk getRouteManager:self.locationManager
135 navigationManager:self.navigationManager];
136 if (self.routeManager) {
137 NSLog(@"RouteManager successfully initialized");
138 }
139 }
140 // [objc_NavigineSdk_getRouteManager]
141
142 // [objc_NavigineSdk_getAsyncRouteManager]
143 // Get AsyncRouteManager for async route operations
144 if (self.locationManager && self.navigationManager) {
145 self.asyncRouteManager = [self.sdk getAsyncRouteManager:self.locationManager
146 navigationManager:self.navigationManager];
147 if (self.asyncRouteManager) {
148 NSLog(@"AsyncRouteManager successfully initialized");
149 }
150 }
151 // [objc_NavigineSdk_getAsyncRouteManager]
152
153 // [objc_NavigineSdk_getNotificationManager]
154 // Get NotificationManager for notifications
155 if (self.locationManager) {
156 self.notificationManager = [self.sdk getNotificationManager:self.locationManager];
157 if (self.notificationManager) {
158 NSLog(@"NotificationManager successfully initialized");
159 }
160 }
161 // [objc_NavigineSdk_getNotificationManager]
162
163 // [objc_NavigineSdk_getMeasurementManager]
164 // Get MeasurementManager for measurements
165 if (self.locationManager) {
166 self.measurementManager = [self.sdk getMeasurementManager:self.locationManager];
167 if (self.measurementManager) {
168 NSLog(@"MeasurementManager successfully initialized");
169 }
170 }
171 // [objc_NavigineSdk_getMeasurementManager]
172
173 // [objc_NavigineSdk_getLocationListManager]
174 // Get LocationListManager for location list operations
175 self.locationListManager = [self.sdk getLocationListManager];
176 if (self.locationListManager) {
177 NSLog(@"LocationListManager successfully initialized");
178 }
179 // [objc_NavigineSdk_getLocationListManager]
180
181 // [objc_NavigineSdk_getStorageManager]
182 // Get StorageManager for working with storages
183 self.storageManager = [self.sdk getStorageManager];
184 if (self.storageManager) {
185 NSLog(@"StorageManager successfully initialized");
186 }
187 // [objc_NavigineSdk_getStorageManager]
188
189 // [objc_NavigineSdk_getMqttSession]
190 // Get MqttSession for publishing position data via MQTT
191 if (self.navigationManager) {
192 self.mqttSession = [self.sdk getMqttSession:self.navigationManager];
193 if (self.mqttSession) {
194 NSLog(@"MqttSession successfully initialized");
195 }
196 }
197 // [objc_NavigineSdk_getMqttSession]
198 }
199
203 - (void)printSdkInfo {
204 NSLog(@"=== Navigine SDK Information ===");
205 NSLog(@"SDK Version: %@", [NCNavigineSdk getVersion]);
206 NSLog(@"Device ID: %@", [NCNavigineSdk getDeviceId]);
207 NSLog(@"Relative Time: %lld", [NCNavigineSdk getRelativeTime]);
208 NSLog(@"LocationManager: %@", self.locationManager ? @"available" : @"unavailable");
209 NSLog(@"NavigationManager: %@", self.navigationManager ? @"available" : @"unavailable");
210 NSLog(@"ZoneManager: %@", self.zoneManager ? @"available" : @"unavailable");
211 NSLog(@"RouteManager: %@", self.routeManager ? @"available" : @"unavailable");
212 NSLog(@"AsyncRouteManager: %@", self.asyncRouteManager ? @"available" : @"unavailable");
213 NSLog(@"NotificationManager: %@", self.notificationManager ? @"available" : @"unavailable");
214 NSLog(@"MeasurementManager: %@", self.measurementManager ? @"available" : @"unavailable");
215 NSLog(@"LocationListManager: %@", self.locationListManager ? @"available" : @"unavailable");
216 NSLog(@"StorageManager: %@", self.storageManager ? @"available" : @"unavailable");
217 NSLog(@"MqttSession: %@", self.mqttSession ? @"available" : @"unavailable");
218 }
219
224 NSLog(@"=== Manager Usage Demonstration ===");
225
226 // LocationManager usage example
227 if (self.locationManager) {
228 NSLog(@"LocationManager ready for location operations");
229 // Add code here for loading locations, working with them, etc.
230 }
231
232 // NavigationManager usage example
233 if (self.navigationManager) {
234 NSLog(@"NavigationManager ready for positioning");
235 // Add code here for getting position, setting up listeners, etc.
236 }
237
238 // ZoneManager usage example
239 if (self.zoneManager) {
240 NSLog(@"ZoneManager ready for zone operations");
241 // Add code here for setting up zones, handling enter/exit events, etc.
242 }
243
244 // RouteManager usage example
245 if (self.routeManager) {
246 NSLog(@"RouteManager ready for route building");
247 // Add code here for building routes, setting destination points, etc.
248 }
249
250 // AsyncRouteManager usage example
251 if (self.asyncRouteManager) {
252 NSLog(@"AsyncRouteManager ready for async route operations");
253 // Add code here for creating routing sessions, etc.
254 }
255
256 // NotificationManager usage example
257 if (self.notificationManager) {
258 NSLog(@"NotificationManager ready for notifications");
259 // Add code here for setting up beacon notifications, etc.
260 }
261
262 // MeasurementManager usage example
263 if (self.measurementManager) {
264 NSLog(@"MeasurementManager ready for measurements");
265 // Add code here for managing measurement generators, etc.
266 }
267
268 // LocationListManager usage example
269 if (self.locationListManager) {
270 NSLog(@"LocationListManager ready for location list operations");
271 // Add code here for getting available locations list, etc.
272 }
273
274 // StorageManager usage example
275 if (self.storageManager) {
276 NSLog(@"StorageManager ready for storage operations");
277 // Add code here for creating storages, managing data, etc.
278 }
279
280 // MqttSession usage example
281 if (self.mqttSession) {
282 NSLog(@"MqttSession ready for publishing position data via MQTT");
283 // Add code here for connecting to MQTT broker, publishing positions, etc.
284 }
285 }
286
290 - (void)demonstrateObjectiveCFeatures {
291 NSLog(@"=== Objective-C Features Demonstration ===");
292
293 // Using blocks for async operations
294 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
295 // Async operation
296 dispatch_async(dispatch_get_main_queue(), ^{
297 NSLog(@"Async operation completed");
298 });
299 });
300
301 // Using KVO (Key-Value Observing) - example
302 [self addObserver:self forKeyPath:@"locationManager" options:NSKeyValueObservingOptionNew context:nil];
303
304 // Using categories (if they were defined)
305 // [self.sdk performCustomOperation];
306
307 // Using selectors
308 SEL selector = @selector(printSdkInfo);
309 if ([self respondsToSelector:selector]) {
310 [self performSelector:selector];
311 }
312 }
313
317 - (void)observeValueForKeyPath:(NSString *)keyPath
318 ofObject:(id)object
319 change:(NSDictionary<NSKeyValueChangeKey,id> *)change
320 context:(void *)context {
321 if ([keyPath isEqualToString:@"locationManager"]) {
322 NSLog(@"LocationManager changed");
323 }
324 }
325
329 - (void)runExample {
330 [self printSdkInfo];
331 [self demonstrateManagersUsage];
332 [self demonstrateObjectiveCFeatures];
333 }
334
335- (void)dealloc {
336 [self removeObserver:self forKeyPath:@"locationManager"];
337}
338
339@end
340
344int main(int argc, const char * argv[]) {
345 @autoreleasepool {
346 NavigineSdkExample *example = [[NavigineSdkExample alloc] init];
347 [example runExample];
348 }
349 return 0;
350}