13 [
self setupZoneListener];
21- (void)initializeSdk {
25 self.sdk = [NCNavigineSdk getInstance];
30 [
self.sdk setUserHash:@"USER-HASH-HERE"];
35 [
self.sdk setServer:@"https://custom.navigine.com"];
40 self.locationManager = [
self.sdk getLocationManager];
45 self.navigationManager = [
self.sdk getNavigationManager:
self.locationManager];
50 self.zoneManager = [
self.sdk getZoneManager:
self.locationManager navigationManager:
self.navigationManager];
54 NSLog(
@"LocationManager, NavigationManager and ZoneManager successfully initialized");
56 }
@catch (NSException *exception) {
57 NSLog(
@"Error initializing SDK: %@", exception.reason);
64- (void)setupZoneListener {
71- (void)demonstrateZoneManagerMethods {
73 NSLog(
@"ZoneManager not initialized");
79 [
self.zoneManager addZoneListener:
self.zoneListener];
80 NSLog(
@"Added zone listener");
84 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
87 [
self.zoneManager removeZoneListener:
self.zoneListener];
88 NSLog(
@"Removed zone listener");
96- (void)demonstrateZoneEventUsage:(NCZoneEvent *)zoneEvent {
97 if (zoneEvent == nil) {
98 NSLog(
@"ZoneEvent is nil");
104 NCZoneEventType type = zoneEvent.type;
105 NSLog(
@"Zone event type: %ld", (
long)type);
110 int32_t locationId = zoneEvent.locationId;
111 NSLog(
@"Zone location ID: %d", locationId);
116 int32_t sublocationId = zoneEvent.sublocationId;
117 NSLog(
@"Zone sublocation ID: %d", sublocationId);
122 int32_t
id = zoneEvent.id;
123 NSLog(
@"Zone ID: %d",
id);
128 NSString *name = zoneEvent.name;
129 NSLog(
@"Zone name: %@", name);
134 NSString *alias = zoneEvent.alias;
135 NSLog(
@"Zone alias: %@", alias);
140 NCZoneEvent *newZoneEvent = [[NCZoneEvent alloc] initWithType:NCZoneEventTypeEnter
146 NSLog(
@"Created new zone event: %@ (%@)", newZoneEvent.name, newZoneEvent.alias);
153- (void)demonstrateZoneEventTypes {
156 NSLog(
@"Available zone event types:");
157 NSLog(
@" - NCZoneEventTypeEnter: %ld", (
long)NCZoneEventTypeEnter);
158 NSLog(
@" - NCZoneEventTypeExit: %ld", (
long)NCZoneEventTypeExit);
165- (void)demonstrateAdvancedZoneFeatures {
166 NSLog(
@"=== Advanced Zone Features ===");
173 ZoneListenerImpl *listener1 = [[
ZoneListenerImpl alloc] initWithExample:
self];
174 ZoneListenerImpl *listener2 = [[
ZoneListenerImpl alloc] initWithExample:
self];
178 [
self.zoneManager addZoneListener:listener1];
179 NSLog(
@"Added first zone listener");
182 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
185 [
self.zoneManager addZoneListener:listener2];
186 NSLog(
@"Added second zone listener");
189 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
193 [
self.zoneManager removeZoneListener:listener1];
194 NSLog(
@"Removed first zone listener");
197 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
200 [
self.zoneManager removeZoneListener:listener2];
201 NSLog(
@"Removed second zone listener");
211- (void)demonstrateZoneEventSimulation {
212 NSLog(
@"=== Zone Event Simulation ===");
215 NSArray<NCZoneEvent *> *simulatedEvents = @[
216 [[NCZoneEvent alloc] initWithType:NCZoneEventTypeEnter locationId:12345 sublocationId:1 id:100 name:@"Entrance Zone" alias:@"entrance"],
217 [[NCZoneEvent alloc] initWithType:NCZoneEventTypeExit locationId:12345 sublocationId:1 id:100 name:@"Entrance Zone" alias:@"entrance"],
218 [[NCZoneEvent alloc] initWithType:NCZoneEventTypeEnter locationId:12345 sublocationId:1 id:101 name:@"Meeting Room" alias:@"meeting_room"],
219 [[NCZoneEvent alloc] initWithType:NCZoneEventTypeEnter locationId:12345 sublocationId:1 id:102 name:@"Cafeteria" alias:@"cafeteria"],
220 [[NCZoneEvent alloc] initWithType:NCZoneEventTypeExit locationId:12345 sublocationId:1 id:101 name:@"Meeting Room" alias:@"meeting_room"],
224 for (
int i = 0; i < simulatedEvents.count; i++) {
225 NCZoneEvent *
event = simulatedEvents[i];
226 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)((i + 1) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
227 NSLog(
@"Simulated zone event: %ld - %@ (%@)", (
long)event.type, event.name, event.alias);
228 [
self demonstrateZoneEventUsage:event];
236- (void)demonstrateZoneListenerManagement {
237 NSLog(
@"=== Zone Listener Management ===");
244 ZoneListenerImpl *testListener = [[
ZoneListenerImpl alloc] initWithExample:
self];
247 [
self.zoneManager addZoneListener:testListener];
248 NSLog(
@"Added test zone listener");
251 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
253 [
self.zoneManager removeZoneListener:testListener];
254 NSLog(
@"Removed test zone listener");
265 [
self.zoneManager removeZoneListener:
self.zoneListener];
274 NSLog(
@"=== ZoneManager Example ===");
276 [
self demonstrateZoneManagerMethods];
277 [
self demonstrateZoneEventTypes];
278 [
self demonstrateZoneListenerManagement];
279 [
self demonstrateAdvancedZoneFeatures];
280 [
self demonstrateZoneEventSimulation];
283 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
285 NSLog(
@"=== Example completed ===");
294@interface ZoneListenerImpl : NSObject <NCZoneListener>
296@property (nonatomic, weak) ZoneManagerExample *example;
298- (instancetype)initWithExample:(ZoneManagerExample *)example;
302@implementation ZoneListenerImpl
304- (instancetype)initWithExample:(ZoneManagerExample *)example {
307 self.example = example;
313- (void)onZoneEvent:(NCZoneEvent *)zoneEvent {
314 NSLog(
@"Zone event detected");
315 [
self.example demonstrateZoneEventUsage:zoneEvent];
324int main(
int argc,
const char * argv[]) {
327 [example runExample];
330 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10.0]];