-1

首先,对不起我的英语。我遇到了一个创建多个本地通知的应用程序的问题。我将它们安排在一个 for 循环中:

for (int i = 0; i < 100 ; i++) {
    compteur++;

    UILocalNotification *prototypeNotification = [[UILocalNotification alloc] init];
    prototypeNotification.timeZone = [NSTimeZone defaultTimeZone];

    prototypeNotification.applicationIconBadgeNumber = 0;
    prototypeNotification.alertBody = @"ALERTE PILULE !!!!!";
    prototypeNotification.alertAction = @"Ok";
    [prototypeNotification setSoundName:UILocalNotificationDefaultSoundName];
    prototypeNotification.fireDate = itemDate;

    [[UIApplication sharedApplication] scheduleLocalNotification:prototypeNotification];
    [prototypeNotification release];

    itemDate = [[NSCalendar currentCalendar] dateByAddingComponents:comps toDate:itemDate options:0];


    if (compteur == 21) {
        compteur = 0;
        itemDate = [[NSCalendar currentCalendar] dateByAddingComponents:comps2 toDate:itemDate options:0];

    }
}

当firedate来了时,它运行良好,但有时它不仅显示一个,而且显示2个或3个或6个警报......我就是找不到原因......有人可以帮助我吗?谢谢

4

1 回答 1

0
- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; 
    //here you can undo many of the changes made on entering the background.
    UIApplication *APP =[UIApplication sharedApplication];
     NSArray *oldnotification = [APP scheduledLocalNotifications];
    if (oldnotification>=0)
    {
         [APP cancelAllLocalNotifications];
    }
}

您是否在上面的模块中添加此代码..以取消旧通知?

于 2013-08-24T07:40:14.897 回答