本地通知问题

时间:2013-03-20 05:55:56

标签: ios objective-c uilocalnotification

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

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

建议我做错了什么

2 个答案:

答案 0 :(得分:1)

您是否已将此代码放入您的app delegate?

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

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

答案 1 :(得分:0)

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

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

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

以上方法被称为。

希望这会对你有所帮助。

一切顺利!!!