多UILocalNotification(Multi UILocalNotification)

编程入门 行业动态 更新时间:2024-10-27 18:32:56
UILocalNotification(Multi UILocalNotification)

你好,我有UILocalNotification问题。 我从服务器接收通知我将Json Array存储在Mutable array 。 喜欢 :

idnoty *通知标题idnoty *通知标题

当我尝试这段代码时:

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 ]; }

最后,当我从服务器收到2个或更多通知时。 此代码显示最后一次Notitfication。

杰森:代码

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; }

谢谢

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

最满意答案

您不应每次在循环内调用[[UIApplication sharedApplication] cancelAllLocalNotifications]。

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

更多推荐

本文发布于:2023-08-03 10:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386883.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UILocalNotification   Multi

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!