0

は、私は私が元第三swichのためpreticular 1 nofticationをキャンセルする必要がありませんが、第三通知すべてのローカル通知をキャンセルしないようにする方法。単一の通知をキャンセルしたり

をキャンセル

-(IBAction)switchingbtn:(id)sender 
{ 
    UISwitch *onoff = (UISwitch *) sender; 
    UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    if(onoff.on) 
    { 
     NSLog(@"Shedule notification"); 


    int tagValue=[sender tag]; 

    NSMutableDictionary *dict = (NSMutableDictionary *)[alarmsArray objectAtIndex:tagValue]; 


    NSDate *firedate = [dict objectForKey:@"date"]; 
    NSLog(@"fire date is %@", firedate); 
    localNotif.fireDate = firedate; 

    localNotif.alertBody = @"Start Exercise"; 
    localNotif.applicationIconBadgeNumber = 0; 

    // localNotif.timeZone =[NSTimeZone timeZoneForSecondsFromGMT:0]; 
    localNotif.timeZone = [NSTimeZone systemTimeZone]; 
    localNotif.repeatInterval = kCFCalendarUnitDay; 


    // [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; //**Not working** 
    [localNotif release]; 

} 

に対応するスイッチを使用して、各セルのためのリマインダーを設定しなかった次のようにテーブルビューを持っている作品

else 
    { 
// Cancel a notification not works 
     // [[UIApplication sharedApplication] cancelLocalNotification:localNotif]; 

     [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
    NSLog(@"cancel notification"); 
} 

答えて

1

これまでの単一の通知をキャンセルする最も良い方法は、userInfo辞書を持つ通知を作成することです。この辞書には、IDキーの通知ID値を追加できます。通知IDを追跡し(plist、SQLデータベースなどに保存する)、通知を削除する必要がある場合は、スケジュールされたnotifをUIApplicationインスタンスに問い合わせてIDでフィルタリングするだけで、その通知のキャンセルメソッドを送信するだけです。

0

ここにあなたが

- (void)CancelExistingNotification { 
//cancel alarm 
UIApplication *app = [UIApplication sharedApplication]; 
NSArray *eventArray = [app scheduledLocalNotifications]; 
for (int i=0; i<[eventArray count]; i++) 
{ 
    UILocalNotification* oneEvent = [eventArray objectAtIndex:i]; 
    NSDictionary *userInfoCurrent = oneEvent.userInfo; 
    NSString *uid=[NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"notificationID"]]; 
    if ([uid isEqualToString:[NSString stringWithFormat:@"%i",self.notificationID]]) 
    { 
     //Cancelling local notification 

     [app cancelLocalNotification:oneEvent]; 
     break; 
    } 
} 

}

「self.notificationID」を望んでいたコードがあるが、広いヘルプNSUserDefaultsアプリケーションがロードされているalarmObjectのようなカスタムオブジェクトのプロパティから来ています。

関連する問題