通知fireTime无法正常工作.在iOS中立即发送通知 [英] Notification fireTime not working. Sends notifications immediately in ios

查看:43
本文介绍了通知fireTime无法正常工作.在iOS中立即发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码在特定时间发送本地通知.从一个方法调用时它工作正常,但是当我从另一个方法调用时,它不起作用.

I have used the following code to send the local notification in particular time. It works fine when calling from a method but when i am calling from another method its not working.

代码如下:

-(void)notificationUserInfo:(NSDictionary *)notificationData
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy HH:mm"];

NSString *tipid = [notificationData objectForKey:@"receivedTipsId"];
NSString *currentDate = [notificationData objectForKey:@"receivedDate"];
NSString *tipsCategoryid = [notificationData objectForKey:@"categoryId"];
NSString *todayDateTime = [notificationData objectForKey:@"todayDate"];
NSString *categoryName = [notificationData objectForKey:@"categoryName"];
NSString *tipsForNotification = [notificationData objectForKey:@"tipsForNotification"];
NSString *cardType = [notificationData objectForKey:@"cardType"];

//Assigning the notification contents
NSDate *updatedDateFormat = [dateFormat dateFromString:todayDateTime];
notification.fireDate = updatedDateFormat;
notification.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:tipid, @"receivedTipsId", currentDate, @"receivedDate", tipsCategoryid, @"categoryId", cardType, @"cardType", nil];
notification.alertBody = [NSString stringWithFormat:@"%@: %@",categoryName, tipsForNotification];
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

谢谢.

推荐答案

这是由于时间和日期格式存在问题.当我使用此方法时,我已将firedate指定为过去的日期.例如,我使用的是 MM/dd/yyyy .

This is because of problem with time and date format. When i used this method, I have given the firedate as past date. eg., instead of dd/MM/yyyy i used MM/dd/yyyy.

因此 2014年12月12日返回为 2014年12月11日.因此,在安排了通知之后,便会立即收到通知.

So 11/12/2014 is returned as 12/11/2014. So the notification is received immediately after the notification scheduled.

这篇关于通知fireTime无法正常工作.在iOS中立即发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆