2

異なる時間と日付がスケジュールされた複数の UILocalNotification を作成しようとしています。ここでいくつかの答えを見つけて、これを作っています:

- (void)applicationDidEnterBackground:(UIApplication *)application{

//1
NSCalendar *gregcalendar1 = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *datecomponent1 = [gregcalendar1 components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];

[datecomponent1 setYear:2013];
[datecomponent1 setMonth:7];
[datecomponent1 setDay:21];
[datecomponent1 setHour:10];
[datecomponent1 setMinute:31];

UIDatePicker *dd1 = [[UIDatePicker alloc]init];
[dd1 setDate:[gregcalendar1 dateFromComponents:datecomponent1]];


UILocalNotification *notification1 = [[UILocalNotification alloc]init];
[notification1 setAlertBody:@"01"];
[notification1 setFireDate:dd1.date];
[notification1 setTimeZone:[NSTimeZone defaultTimeZone]];



//2
NSCalendar *gregcalendar2 = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *datecomponent2 = [gregcalendar2 components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];

[datecomponent2 setYear:2013];
[datecomponent2 setMonth:7];
[datecomponent2 setDay:21];
[datecomponent2 setHour:10];
[datecomponent2 setMinute:32];

UIDatePicker *dd2 = [[UIDatePicker alloc]init];
[dd2 setDate:[gregcalendar2 dateFromComponents:datecomponent2]];


UILocalNotification *notification2 = [[UILocalNotification alloc]init];
[notification2 setAlertBody:@"02"];
[notification2 setFireDate:dd2.date];
[notification2 setTimeZone:[NSTimeZone defaultTimeZone]];



//3
NSCalendar *gregcalendar3 = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *datecomponent3 = [gregcalendar3 components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];

[datecomponent3 setYear:2013];
[datecomponent3 setMonth:7];
[datecomponent3 setDay:21];
[datecomponent3 setHour:10];
[datecomponent3 setMinute:33];

UIDatePicker *dd3 = [[UIDatePicker alloc]init];
[dd3 setDate:[gregcalendar3 dateFromComponents:datecomponent3]];


UILocalNotification *notification3 = [[UILocalNotification alloc]init];
[notification3 setAlertBody:@"03"];
[notification3 setFireDate:dd3.date];
[notification3 setTimeZone:[NSTimeZone defaultTimeZone]];


[application setScheduledLocalNotifications:@[notification1, notification2, notification3]];}

ただし、一部の通知はランダムに機能し、一部は機能しません。複数の通知をスケジュールするにはどうすればよいですか。

助けてくれてありがとう...

4

0 に答える 0