Search code examples
objective-cjsonios6uilocalnotification

Multi UILocalNotification


hello i have problem with UILocalNotification. i am taking notification from a server an i store the Json Array in a Mutable array. Like :

idnoty * id of notification titlenoty * title of notification

when i try this code :

UILocalNotification *notif;
NSMutableArray *notifications = [[NSMutableArray alloc] init];
for(int i=0 ; i<[idnoty count]; i++){
         notif=[[UILocalNotification alloc]init];
   if (notif == nil) return;

NSLog(@" H LOOP %i",i);

notif.fireDate = [NSDate date];
notif.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
[localNotification setHasAction:YES];
localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.alertBody = [titlenoty objectAtIndex:i];
localNotification.applicationIconBadgeNumber = i+1;

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification ];
}

finaly when i have 2 and more notifications from the server. this code displaying the last Notitfication.

json: Code

content =     (
                {
            active = 1;
            descr = sdescr;
            entrydate = "2013-05-15";
            id = 48;
            pid = 11;
            title = dasdsad;
        },
                {
            active = 1;
            descr = sdescr;
            entrydate = "2013-05-16";
            id = 49;
            pid = 11;
            title = MALAKA;
        },
                {
            active = 1;
            descr = sdescr;
            entrydate = "2013-05-16";
            id = 50;
            pid = 11;
            title = dasdsadsadsadsadsadsadsagdfggffggfdgdfgdfgdfgdfgdfgdfgdfgdf;
        }
    );
    "total_rows" = 3;
}

Thanks


Solution

  • You should not call [[UIApplication sharedApplication] cancelAllLocalNotifications] inside the loop every time.