我花了一天的時間閱讀所有「如何取消本地通知」問題和答案。畢竟,我想出了我自己的解決方案,但顯然它不工作。 我有我的所有計劃的通知的實現代碼如下....取消本地通知不起作用
在.h文件我已經
@property (strong, nonatomic) UILocalNotification *theNotification;
,然後在M檔:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
theNotification = [notificationArray objectAtIndex:indexPath.row];
NSLog(@"Notification to cancel: %@", [theNotification description]);
// NSLOG Perfectly describes the notification to be cancelled. But then It will give me "unrecognized selector"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Local Reminder"
message:@"Cancel local reminder ?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
[alertView show];
[alertView release];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"Cancel");
}else{
NSLog(@"Ok");
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
}
}
如果我點擊「確定「我得到: 2012-02-04 03:34:48.806第三次測試[8921:207] - [__ NSCFType encodeWithCoder:]:無法識別的選擇器發送到實例0x890ae90 編程接收信號」SIGABRT「。
如果我完全可以識別要取消的通知爲什麼它會給我這個?
我試圖找到一種方法,其中1 - 我不需要關閉控制器2 - 可視化通知被刪除3 - 不必每次都設置特定的按鍵。你的答案是完全有效的,我只是爲了獲得更好的視覺效果而多做一點工作。儘管感謝您的回答。我會接受並投票。 – Farini 2012-02-04 20:24:09
請注意,這僅適用於_scheduled_通知;你似乎無法取消通過'presentLocalNotificationNow:'呈現的通知。這隻花了我一年的時間才搞清楚! – 2014-06-12 00:08:00
@Farini隨時編輯我的答案,使其更好:) – Shmidt 2014-06-12 07:16:44