13 [
self setupLocationListListener];
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.locationListManager = [
self.sdk getLocationListManager];
44 NSLog(
@"LocationListManager successfully initialized");
46 }
@catch (NSException *exception) {
47 NSLog(
@"Error initializing SDK: %@", exception.reason);
54- (void)setupLocationListListener {
61- (void)demonstrateLocationListManagerMethods {
63 NSLog(
@"LocationListManager not initialized");
69 [
self.locationListManager addLocationListListener:
self.locationListListener];
70 NSLog(
@"Added location list listener");
75 [
self.locationListManager updateLocationList];
76 NSLog(
@"Requested location list update");
81 NSDictionary<NSNumber *, NCLocationInfo *> *currentLocationList = [
self.locationListManager getLocationList];
82 NSLog(
@"Current location list contains %lu locations", (
unsigned long)currentLocationList.count);
83 [
self demonstrateLocationList:currentLocationList];
87 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
90 [
self.locationListManager removeLocationListListener:
self.locationListListener];
91 NSLog(
@"Removed location list listener");
99- (void)demonstrateLocationList:(NSDictionary<NSNumber *, NCLocationInfo *> *)locationInfos {
100 if (locationInfos.count == 0) {
101 NSLog(
@"Location list is empty");
105 NSLog(
@"=== Location List ===");
106 [
locationInfos enumerateKeysAndObjectsUsingBlock:^(NSNumber *locationId, NCLocationInfo *locationInfo, BOOL *stop) {
107 [
self demonstrateLocationInfo:locationInfo];
109 NSLog(
@"====================");
115- (void)demonstrateLocationInfo:(NCLocationInfo *)locationInfo {
118 int32_t
id = locationInfo.id;
119 NSLog(
@"Location ID: %d",
id);
124 int32_t version = locationInfo.version;
125 NSLog(
@"Location version: %d", version);
130 NSString *name = locationInfo.name;
131 NSLog(
@"Location name: %@", name);
140- (void)demonstrateErrorHandling:(NSError *)error {
141 NSLog(
@"Handling location list error:");
142 NSLog(
@" Error message: %@", error.localizedDescription);
143 NSLog(
@" Error domain: %@", error.domain);
144 NSLog(
@" Error code: %ld", (
long)error.code);
150- (void)demonstrateAdvancedLocationListFeatures {
151 NSLog(
@"=== Advanced Location List Features ===");
163 [
self.locationListManager addLocationListListener:listener1];
164 NSLog(
@"Added first location list listener");
167 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
170 [
self.locationListManager addLocationListListener:listener2];
171 NSLog(
@"Added second location list listener");
175 [
self.locationListManager updateLocationList];
177 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
181 [
self.locationListManager removeLocationListListener:listener1];
182 NSLog(
@"Removed first location list listener");
185 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
188 [
self.locationListManager removeLocationListListener:listener2];
189 NSLog(
@"Removed second location list listener");
199- (void)demonstrateLocationListSimulation {
200 NSLog(
@"=== Location List Simulation ===");
203 NSDictionary<NSNumber *, NCLocationInfo *> *simulatedLocations = @{
204 @1001: [[NCLocationInfo alloc] initWithId:1001 version:1 name:@"Shopping Mall"],
205 @1002: [[NCLocationInfo alloc] initWithId:1002 version:2 name:@"Office Building"],
206 @1003: [[NCLocationInfo alloc] initWithId:1003 version:1 name:@"Airport Terminal"],
207 @1004: [[NCLocationInfo alloc] initWithId:1004 version:3 name:@"University Campus"],
211 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
212 NSLog(
@"Simulated location list loaded");
213 [
self demonstrateLocationList:simulatedLocations];
217 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
218 NSDictionary<NSNumber *, NCLocationInfo *> *updatedLocations = @{
219 @1001: [[NCLocationInfo alloc] initWithId:1001 version:2 name:@"Shopping Mall - Updated"],
220 @1002: [[NCLocationInfo alloc] initWithId:1002 version:3 name:@"Office Building - Updated"],
221 @1003: [[NCLocationInfo alloc] initWithId:1003 version:2 name:@"Airport Terminal - Updated"],
222 @1004: [[NCLocationInfo alloc] initWithId:1004 version:4 name:@"University Campus - Updated"],
223 @1005: [[NCLocationInfo alloc] initWithId:1005 version:1 name:@"New Hospital"],
225 NSLog(
@"Simulated location list updated");
226 [
self demonstrateLocationList:updatedLocations];
233- (void)demonstrateLocationListListenerManagement {
234 NSLog(
@"=== Location List Listener Management ===");
244 [
self.locationListManager addLocationListListener:testListener];
245 NSLog(
@"Added test location list listener");
248 [
self.locationListManager updateLocationList];
251 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
253 [
self.locationListManager removeLocationListListener:testListener];
254 NSLog(
@"Removed test location list listener");
262 NSLog(
@"=== LocationListManager Example ===");
264 [
self demonstrateLocationListManagerMethods];
265 [
self demonstrateLocationListListenerManagement];
266 [
self demonstrateAdvancedLocationListFeatures];
267 [
self demonstrateLocationListSimulation];
270 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
271 NSLog(
@"=== Example completed ===");
280@interface LocationListListenerImpl : NSObject <NCLocationListListener>
282@property (nonatomic, weak) LocationListManagerExample *example;
284- (instancetype)initWithExample:(LocationListManagerExample *)example;
288@implementation LocationListListenerImpl
290- (instancetype)initWithExample:(LocationListManagerExample *)example {
293 self.example = example;
299- (void)onLocationListLoaded:(NSDictionary<NSNumber *, NCLocationInfo *> *)locationInfos {
300 NSLog(
@"Location list loaded");
301 [
self.example demonstrateLocationList:locationInfos];
306- (void)onLocationListFailed:(NSError *)error {
307 NSLog(
@"Location list failed");
308 [
self.example demonstrateErrorHandling:error];
317int main(
int argc,
const char * argv[]) {
320 [example runExample];
323 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10.0]];