1

我正在尝试在数组日期与当前日期相同时收到通知,此代码用于此任务

NSDateFormatter *Form = [[NSDateFormatter alloc] init];
    [Form setDateFormat:@"dd/MM/yyyy"];

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    for (int i=0;i<_convertedBdates.count;i++)
    {
        NSDate *date =[Form dateFromString:[_convertedBdates objectAtIndex:i ]];
        NSLog(@"date%@",date);

    if(notification)
        {
            notification.fireDate = date;
            notification.timeZone = [NSTimeZone defaultTimeZone];
            notification.alertBody = @"New ";
            notification.alertAction = @"View";

            notification.soundName = UILocalNotificationDefaultSoundName;
            notification.applicationIconBadgeNumber = 1;
            [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        }
    }

建议我做错了什么

4

2 回答 2

1

您是否将此代码放入您的应用程序委托中?

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    NSLog(@"Notification Received, %@, set for date %@", notification.alertBody, notification.fireDate);
}

如果问题仍然存在,那么我在这里:)

于 2013-03-20T05:59:53.600 回答
0

如果您的 NSDate 小于当前日期,则不会触发通知。如果您在用户生日上设置通知日期,则会发生这种情况。

如果您的应用程序处于运行模式,则:

 - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

上面的方法被调用。

希望这会帮助你。

祝一切顺利 !!!

于 2013-03-20T06:03:34.093 回答