テーブル内のいくつかの行に対して、特定の日時にローカル通知を設定しています。だから考えて
ケース 1: ユーザーが初めてローカル通知を設定するとき、日付ピッカーから日付を選択し、それをローカル通知オブジェクトの firedate に渡します。
NSArray *notificationarray = [[UIApplication sharedApplication]scheduledLocalNotifications];
if([notificationarray count]== 0)
{
m_alarmLocalNotification = [[UILocalNotification alloc] init];
m_alarmLocalNotification.fireDate = DateTime;
m_alarmLocalNotification.timeZone = [NSTimeZone defaultTimeZone];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:m_Name forKey:@"ID"];
m_alarmLocalNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:m_alarmLocalNotification];
case2: 現地通知日の変更。
NSArray *notificationarray = [[UIApplication sharedApplication]scheduledLocalNotifications];
for (int i = 0;i < [notificationarray count];i++)
{
UILocalNotification *notificationObject=[notificationarray objectAtIndex:i];
NSString *Name=[notificationObject.userInfo valueForKey:@"ID"];
if(Name isEqualToString:m_Name])
{
[[UIApplication sharedApplication] cancelLocalNotification:notificationObject];
m_alarmLocalNotification = [[UILocalNotification alloc] init];
m_alarmLocalNotification.fireDate = DateTime;
m_alarmLocalNotification.timeZone = [NSTimeZone defaultTimeZone];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:m_noteName forKey:@"ID"];
m_alarmLocalNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:m_alarmLocalNotification];
}
else
{
m_alarmLocalNotification = [[UILocalNotification alloc] init];
m_alarmLocalNotification.fireDate = DateTime;
m_alarmLocalNotification.timeZone = [NSTimeZone defaultTimeZone];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:m_noteName forKey:@"ID"];
m_alarmLocalNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:m_alarmLocalNotification];
}
}
ケース 3: ローカル通知を削除する。
NSArray *notificationarray = [[UIApplication sharedApplication]scheduledLocalNotifications];
NSLog(@"notification count:%d",[notificationarray count]);
for (int i = 0;i < [notificationarray count];i++)
{
UILocalNotification *notificationObject=[notificationarray objectAtIndex:i];
NSString *Name=[notificationObject.userInfo valueForKey:@"ID"];
if([Name isEqualToString:m_Name])
{
[[UIApplication sharedApplication] cancelLocalNotification:notificationObject];
}
}
直面した問題。0) 自分のやり方が正しいかどうか確信が持てない. 1)アプリを削除してもう一度再インストールしても、デフォルトのスケジュールされた通知配列の割り当てが解除されません。つまり、以前の通知が含まれています。2)セルを削除するたびに、ローカル通知を削除する必要があります。
よろしくランジット