私は自分のアプリで通知をスケジュールし、スヌーズボタンで行動可能な通知を作成しました。スヌーズボタンの処理で、別の通知を作成してスケジュールしました。しかし、私がアプリを起動し、スケジュールされた通知を0の予定の通知と言うと、私は再びそれを殺した後にアプリを起動するときにしようとするとき。その通知を与える。UIApplication共有オブジェクトがスケジュール通知をしていません
どうして私が最初に通知を予定していないのですか?
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forLocalNotification notification: UILocalNotification, completionHandler:() -> Void) {
if identifier == Constants.NOTIFICATION_CATEGORY_ACTION_RESUME {
// do something
} else if identifier == Constants.NOTIFICATION_CATEGORY_ACTION_SNOOZE {
// extracting time from notification user info and scheduling another notification of same time
let userInfo = notification.userInfo
let newNotification = UILocalNotification()
let timeInterval = userInfo!["timeInterval"] as! NSTimeInterval
newNotification.fireDate = NSDate(timeIntervalSinceNow: timeInterval)
if #available(iOS 8.2, *) {
newNotification.alertTitle = Utilities.getLocalizedString("NotificationAlertTitle")
} else {
// Fallback on earlier versions
}
newNotification.alertBody = Utilities.getLocalizedString("NotificationAlertBody")
newNotification.alertAction = Utilities.getLocalizedString("NotificationAlertAction")
newNotification.soundName = UILocalNotificationDefaultSoundName
newNotification.category = Constants.CATEGORY_NAME
// use this to store previous time
let date = NSDate()
newNotification.userInfo = [Constants.NOTIFICATIONUSERINFO_TIMEINTERVAL : timeInterval, Constants.NOTIFICATIONUSERINFO_TAG : Constants.NOTIFICATION_TAG, Constants.NOTIFICATIONUSERINFO_SETTIME : date.timeIntervalSince1970]
UIApplication.sharedApplication().cancelAllLocalNotifications()
UIApplication.sharedApplication().scheduleLocalNotification(newNotification)
}
completionHandler()
}
[docs](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/cancelAllLocalNotifications)にはこのようなことはありません。 –