我正在尝试创建一个应用程序,如果您每天获得总共64个本地通知。所有通知必须不同。到目前为止,我已经写了两个通知,并将他们的激活设置为特定日期。但是当我运行应用程序时,第一个通知以及另一个通知应该在一天后发布。我该如何解决这个问题?!
#import "AppDelegate.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
NSCalendar *gregCalender = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponent = [gregCalender components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
[dateComponent setYear:2013];
[dateComponent setMonth:12];
[dateComponent setHour:20];
[dateComponent setMinute:19];
UIDatePicker *dd = [[UIDatePicker alloc]init];
[dd setDate:[gregCalender dateFromComponents:dateComponent]];
UILocalNotification *notification = [[UILocalNotification alloc]init];
[notification setAlertBody:@"hejsan hoppsan"];
[notification setFireDate:dd.date];
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[notification setSoundName:@"jingle-bells-sms.mp3"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
// --------------------------------------------- ----------------------------------------------
NSCalendar *gregorianCalender = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponent2 = [gregorianCalender components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
[dateComponent2 setYear:2013];
[dateComponent2 setMonth:12];
[dateComponent2 setHour:20];
[dateComponent2 setMinute:20];
UIDatePicker *dd2 = [[UIDatePicker alloc]init];
[dd2 setDate:[gregorianCalender dateFromComponents:dateComponent2]];
UILocalNotification *notification2 = [[UILocalNotification alloc]init];
[notification2 setAlertBody:@"tjena bena"];
[notification2 setFireDate:dd2.date];
[notification2 setTimeZone:[NSTimeZone defaultTimeZone]];
[notification2 setSoundName:@"jingle-bells-sms.mp3"];
[[UIApplication sharedApplication] scheduleLocalNotification:notification2];
}