13 [
self setupNotificationListener];
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.notificationManager = [
self.sdk getNotificationManager:
self.locationManager];
49 NSLog(
@"LocationManager and NotificationManager successfully initialized");
51 }
@catch (NSException *exception) {
52 NSLog(
@"Error initializing SDK: %@", exception.reason);
59- (void)setupNotificationListener {
66- (void)demonstrateNotificationManagerMethods {
68 NSLog(
@"NotificationManager not initialized");
74 [
self.notificationManager addNotificationListener:
self.notificationListener];
75 NSLog(
@"Added notification listener");
79 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
82 [
self.notificationManager removeNotificationListener:
self.notificationListener];
83 NSLog(
@"Removed notification listener");
91- (void)demonstrateNotificationUsage:(NCNotification *)notification {
92 if (notification == nil) {
93 NSLog(
@"Notification is nil");
99 int32_t
id = notification.id;
100 NSLog(
@"Notification ID: %d",
id);
105 NSString *title = notification.title;
106 NSLog(
@"Notification title: %@", title);
111 NSString *content = notification.content;
112 NSLog(
@"Notification content: %@", content);
117 NSString *imageUrl = notification.imageUrl;
118 if (imageUrl != nil && imageUrl.length > 0) {
119 NSLog(
@"Notification image URL: %@", imageUrl);
121 NSLog(
@"Notification has no image URL");
129- (void)demonstrateErrorHandling:(NSError *)error {
130 NSLog(
@"Handling notification error:");
131 NSLog(
@" Error message: %@", error.localizedDescription);
132 NSLog(
@" Error domain: %@", error.domain);
133 NSLog(
@" Error code: %ld", (
long)error.code);
140 NSLog(
@"=== NotificationManager Example ===");
142 [
self demonstrateNotificationManagerMethods];
145 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
146 NSLog(
@"=== Example completed ===");
155@interface NotificationListenerImpl : NSObject <NCNotificationListener>
157@property (nonatomic, weak) NotificationManagerExample *example;
159- (instancetype)initWithExample:(NotificationManagerExample *)example;
163@implementation NotificationListenerImpl
165- (instancetype)initWithExample:(NotificationManagerExample *)example {
168 self.example = example;
174- (void)onNotificationLoaded:(NCNotification *)notification {
175 NSLog(
@"Notification loaded");
176 [
self.example demonstrateNotificationUsage:notification];
181- (void)onNotificationFailed:(NSError *)error {
182 NSLog(
@"Notification failed");
183 [
self.example demonstrateErrorHandling:error];
192int main(
int argc,
const char * argv[]) {
195 [example runExample];
198 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:10.0]];