我正在开发一个伊斯兰祈祷时间应用程序,该应用程序每天提供五个祈祷时间。所以我现在的目标是每天在特定的祈祷时间向用户发送五个通知。然后我为每个祈祷创建了五个通知,为每个通知分配了五个 fireate,我可以收到通知。
但是,我的问题是每次运行应用程序或重新启动应用程序时,我都会在通知中心收到通知,在控制台区域我可以看到所有较旧的通知也已发送(我覆盖了 application:didReceiveLocalNotification: 方法)。
坦率地说,我不是一个经验丰富的开发人员,我真的不明白这一点,我认为我的代码很长。那么有人可以帮助我并告诉我如何做到这一点吗?:) (我的英语不是那么好请宽容)。如果我错过了其他歌曲来告知,请告诉。
这是我的代码;
编辑:我从 viewDidLoad 调用这个方法。
我在阵列中获得了五次打击:
NSSArray *timeArray = @[time0,time1,time2,time3,time4];
我像这样安排了五个 UILocalNotification:
if (localNotification0 != nil) {
[[UIApplication sharedApplication] cancelLocalNotification:localNotification0];
}
NSDate *date0 = [_timeArray objectAtIndex:0];
NSLog(@"date %@",date0);
localNotification0 = [[UILocalNotification alloc] init];
localNotification0.fireDate = date0;
localNotification0.timeZone =[NSTimeZone defaultTimeZone];
NSLog(@"firedate %@",localNotification0.timeZone);
localNotification0.alertBody = @"Se";
localNotification0.soundName = _adhanName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification0];
if (localNotification1 != nil) {
[[UIApplication sharedApplication] cancelLocalNotification:localNotification1];
}
NSDate *date1 = [_timeArray objectAtIndex:1];
localNotification1 = [[UILocalNotification alloc] init];
localNotification1.fireDate = date1;
NSLog(@"firedate %@",localNotification1.fireDate);
localNotification1.timeZone =[NSTimeZone defaultTimeZone];
localNotification1.alertBody = @"Se";
localNotification1.soundName = _adhanName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification1];
[localNotification1 release];
if (localNotification2 != nil) {
[[UIApplication sharedApplication] cancelLocalNotification:localNotification2];
}
NSDate *date2 = [_timeArray objectAtIndex:2];
localNotification2 = [[UILocalNotification alloc] init];
localNotification2.fireDate = date2;
localNotification2.timeZone =[NSTimeZone defaultTimeZone];
NSLog(@"firedate %@",localNotification2.fireDate);
localNotification2.alertBody = @"Se";
localNotification2.soundName = _adhanName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification2];
[localNotification2 release];
if (localNotification3 != nil) {
[[UIApplication sharedApplication] cancelLocalNotification:localNotification3];
}
NSDate *date3 = [_timeArray objectAtIndex:3];
localNotification3 = [[UILocalNotification alloc] init];
localNotification3.fireDate = date3;
localNotification3.timeZone =[NSTimeZone defaultTimeZone];
NSLog(@"firedate %@",localNotification3.fireDate);
localNotification3.alertBody = @"Se";
localNotification3.soundName = _adhanName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification3];
[localNotification3 release];
if (localNotification4 != nil) {
[[UIApplication sharedApplication] cancelLocalNotification:localNotification4];
}
NSDate *date4 = [_timeArray objectAtIndex:4];
localNotification4 = [[UILocalNotification alloc] init];
localNotification4.fireDate = date4;
localNotification4.timeZone =[NSTimeZone defaultTimeZone];
NSLog(@"firedate %@",localNotification4.fireDate);
localNotification4.alertBody = @"Se";
localNotification4.soundName = _adhanName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification4];
[localNotification4 release];
还有其他更简单的方法吗?请帮帮我!