0
我在我的應用程序中關於10個本地通知(不是數組)和它的開關。我用這個代碼cancelLocalNotification不起作用
NSUserDefaults *defaultsB = [NSUserDefaults standardUserDefaults];
UILocalNotification *notification = [[UILocalNotification alloc]init];
if (switcher.on == 1) {
NSCalendar *gregCalendar = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponent = [gregCalendar components:NSYearCalendarUnit | NSWeekCalendarUnit fromDate:[NSDate date]];
[dateComponent setWeekday:1]; // For sunday
[dateComponent setHour:[timeHClass.text integerValue]];
[dateComponent setMinute:[timeMClass.text integerValue]];
NSDate *fireDate = [gregCalendar dateFromComponents:dateComponent];
[notification setAlertBody:textClass1.text];
[notification setFireDate:fireDate];
notification.soundName = @"bells.mp3";
notification.repeatInterval = NSWeekCalendarUnit;
[notification setTimeZone:[NSTimeZone defaultTimeZone]];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[defaultsB setObject:@"ON" forKey:@"SwitchState"];
}
else {
UIApplication *app=[UIApplication sharedApplication];
[app cancelLocalNotification:notification];
[defaultsB setObject:@"OFF" forKey:@"SwitchState"];
}
但是當我關掉通知仍然工作?
我應該保存通知保存在NSUserDefaults不只是開關?
如果它是的如何?
所以你說我應該把在陣列得到消除工作?但方式我的方式沒有工作?我怎麼能把它放在數組中,如果每個通知單開關?...我是初學者 – Faisal
@Faisal如果你正在做的是在你的應用程序中創建一個本地通知,只需取消所有通知[應用程序cancelAllLocalNotifications] ;'。如果你需要取消一個特定的通知,我會建議以下[這個答案](http://stackoverflow.com/questions/7186236/cancelling-a-specific-uilocalnotification)。 – thattyson
感謝它的工作 – Faisal