本地通知问题

问题描述 投票:0回答:2

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

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

建议我做错了什么

ios objective-c uilocalnotification
2个回答
1
投票

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

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

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


0
投票

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

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

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

调用上面的方法。

© www.soinside.com 2019 - 2024. All rights reserved.