Ios 本地通知中的问题未触发
下面是我的代码,我在网上查过了一切都正常,但不知道通知没有被触发,我知道这很简单,但我仍然被困在这里,请帮助Ios 本地通知中的问题未触发,ios,uilocalnotification,Ios,Uilocalnotification,下面是我的代码,我在网上查过了一切都正常,但不知道通知没有被触发,我知道这很简单,但我仍然被困在这里,请帮助 -(void)notification:(NSMutableArray *)nameArray datearray:(NSMutableArray*)datearray; { NSLog(@"name%@",nameArray); NSLog(@"date%@",datearray); "Jodie Hession",
-(void)notification:(NSMutableArray *)nameArray datearray:(NSMutableArray*)datearray;
{
NSLog(@"name%@",nameArray);
NSLog(@"date%@",datearray);
"Jodie Hession",
"John Miller",
"Shane Jarome",
"Sharon Scott",
"Sheron Begley",
"Susan Diaz",
Kate,
John,
Anna,
David,
today,
"After Some day"
)
date(
"14/12/2013 04:35:00",
"18/12/2013 04:35:00",
"04/04/2014 04:35:00",
"01/01/2014 04:35:00",
"29/06/2014 04:35:00",
"05/01/2014 04:35:00",
"18/12/2013 04:35:00",
"20/01/2014 04:35:00",
"22/06/2014 04:35:00",
"29/08/2013 04:35:00",
"15/06/2014 04:35:00",
"22/07/2013 04:35:00",
"31/07/2013 04:35:00"
)
// logic for local notification start
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSDateFormatter *Form=[[[NSDateFormatter alloc]init]autorelease];
[Form setDateFormat:@"dd/MM/yyyy hh:mm:ss"];
UILocalNotification *notification = [[UILocalNotification alloc] init];
for (int i=0;i<datearray.count;i++)
{
NSDate *date =[Form dateFromString:[datearray objectAtIndex:i ]];
NSLog(@"%@",date);
if(notification)
{
notification.fireDate = date;
// if(notification.fireDate == date){
//
// notification.applicationIconBadgeNumber = 1;
//
// }
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = [NSString stringWithFormat:@"Today is %@\'s Birthday",[nameArray objectAtIndex:i]];
notification.alertAction = @"View";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
NSLog(@"fire date%@", notification.fireDate);
// fire date2013-07-30 23:05:00 +0000
在我的应用程序delegete中
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"Notification Received, %@, set for date %@", notification.alertBody, notification.fireDate);
}
看起来这是您使用的日期格式的问题。我是在格林尼治时间用setDateFormat:@“yyyy-MM-dd HH:MM:ss Z”制作的,现在工作正常 以下是您的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSMutableArray *datearray = [[NSMutableArray alloc]initWithObjects:
@"23/07/2013 12:33:00",
@"23/07/2013 12:33:05",
@"23/07/2013 12:33:10",
@"23/07/2013 12:33:15",
@"23/07/2013 12:33:20",
@"23/07/2013 12:33:25",
@"23/07/2013 12:33:30",
@"23/07/2013 12:33:35",
@"23/07/2013 12:33:40",
@"23/07/2013 12:33:45",
@"23/07/2013 12:33:50",
@"23/07/2013 12:33:55",
@"23/07/2013 12:34:00",
nil];
NSMutableArray *nameArray = [[NSMutableArray alloc]initWithObjects:
@"Jodie Hession",
@"John Miller",
@"Shailesh Mistry",
@"Shane Jarome",
@"Sharon Scott",
@"Sheron Begley",
@"Susan Diaz",
@"Kate",
@"John",
@"Anna",
@"David",
@"today",
@"After Some day",
nil];
[self notification:nameArray datearray:datearray];
}
-(void)notification:(NSMutableArray *)nameArray datearray:(NSMutableArray*)datearray;
{
NSDateFormatter *Form = [[NSDateFormatter alloc]init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *notification = [[UILocalNotification alloc] init];
for (int i=0;i<datearray.count;i++)
{
//[Form setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
//NSDate *date =[Form dateFromString:[datearray objectAtIndex:i]];
[Form setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSDate *date =[Form dateFromString:[[datearray objectAtIndex:i] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]];
NSLog(@"%@",date);
if(notification)
{
// un-comment this for current date time
/*[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5*i]];
NSLog(@" %@",[NSDate dateWithTimeIntervalSinceNow:5*i]);*/
//comment this for current date time
[notification setFireDate:date];
NSLog(@" %@",date);
//notification.fireDate = date;
//if(notification.fireDate == date){
//}
notification.applicationIconBadgeNumber = i;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = [NSString stringWithFormat:@"Today is %@\'s Birthday",[nameArray objectAtIndex:i]];
notification.alertAction = @"View";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
NSLog(@"fire date%@", notification.fireDate);
}
}
-(void)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
NSMutableArray*datearray=[[NSMutableArray alloc]initWithObjects:
@"23/07/2013 12:33:00",
@"23/07/2013 12:33:05",
@"23/07/2013 12:33:10",
@"23/07/2013 12:33:15",
@"23/07/2013 12:33:20",
@"23/07/2013 12:33:25",
@"23/07/2013 12:33:30",
@"23/07/2013 12:33:35",
@"23/07/2013 12:33:40",
@"23/07/2013 12:33:45",
@"23/07/2013 12:33:50",
@"23/07/2013 12:33:55",
@"23/07/2013 12:34:00",
零];
NSMutableArray*nameArray=[[NSMutableArray alloc]initWithObjects:
@“朱迪·海森”,
@“约翰·米勒”,
@“Shailesh Mistry”,
@“Shane Jarome”,
@“莎伦·斯科特”,
@“Sheron Begley”,
@“苏珊·迪亚兹”,
@“凯特”,
@“约翰”,
@“安娜”,
@“大卫”,
@“今天”,
@“过了一天”,
零];
[自我通知:nameArray datearray:datearray];
}
-(void)通知:(NSMutableArray*)nameArray datearray:(NSMutableArray*)datearray;
{
NSDateFormatter*Form=[[NSDateFormatter alloc]init];
[[UIApplication sharedApplication]取消所有本地通知];
UILocalNotification*通知=[[UILocalNotification alloc]init];
对于(int i=0;我检查过最小化应用程序了吗?据我所知,通知不适用于循环。如果您运行一个值,它正在运行!让我研究更多信息。无论何时您得到什么,请发布您的答案。非常感谢,因为我的日期格式化程序是“20/01/2014 11:59:00”,我们尝试更改它yyyy-MM-dd HH:MM:ss Z,因此,由于该日期变为空,如何处理此问题?您是否从Web服务获取这些日期时间?是的,从每个位置都有一些来自facebook,一些来自用户,一些来自通讯簿。那么我们如何更改此格式化程序?因此,nsdate不会变为空编辑:删除+530
并替换 /
和-
。现在可以了吗?是的,先生,非常感谢您这个日期格式化程序总是让我困惑
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSMutableArray *datearray = [[NSMutableArray alloc]initWithObjects:
@"23/07/2013 12:33:00",
@"23/07/2013 12:33:05",
@"23/07/2013 12:33:10",
@"23/07/2013 12:33:15",
@"23/07/2013 12:33:20",
@"23/07/2013 12:33:25",
@"23/07/2013 12:33:30",
@"23/07/2013 12:33:35",
@"23/07/2013 12:33:40",
@"23/07/2013 12:33:45",
@"23/07/2013 12:33:50",
@"23/07/2013 12:33:55",
@"23/07/2013 12:34:00",
nil];
NSMutableArray *nameArray = [[NSMutableArray alloc]initWithObjects:
@"Jodie Hession",
@"John Miller",
@"Shailesh Mistry",
@"Shane Jarome",
@"Sharon Scott",
@"Sheron Begley",
@"Susan Diaz",
@"Kate",
@"John",
@"Anna",
@"David",
@"today",
@"After Some day",
nil];
[self notification:nameArray datearray:datearray];
}
-(void)notification:(NSMutableArray *)nameArray datearray:(NSMutableArray*)datearray;
{
NSDateFormatter *Form = [[NSDateFormatter alloc]init];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *notification = [[UILocalNotification alloc] init];
for (int i=0;i<datearray.count;i++)
{
//[Form setDateFormat:@"yyyy-MM-dd HH:mm:ss Z"];
//NSDate *date =[Form dateFromString:[datearray objectAtIndex:i]];
[Form setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSDate *date =[Form dateFromString:[[datearray objectAtIndex:i] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]];
NSLog(@"%@",date);
if(notification)
{
// un-comment this for current date time
/*[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5*i]];
NSLog(@" %@",[NSDate dateWithTimeIntervalSinceNow:5*i]);*/
//comment this for current date time
[notification setFireDate:date];
NSLog(@" %@",date);
//notification.fireDate = date;
//if(notification.fireDate == date){
//}
notification.applicationIconBadgeNumber = i;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = [NSString stringWithFormat:@"Today is %@\'s Birthday",[nameArray objectAtIndex:i]];
notification.alertAction = @"View";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
NSLog(@"fire date%@", notification.fireDate);
}
}