-
Notifications
You must be signed in to change notification settings - Fork 34
Validate notification fire date before scheduling #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| private func localNotificationScheduleNotification( | ||
| contentProvider: LocalNotificationContentProvider | ||
| ) -> Promise<Void> { | ||
| if !self.isFireDateValid(contentProvider.fireDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Без отрицания?
guard self.isFireDateValid(contentProvider.fireDate) else {
return Promise(error: Error.badFireDate)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кстати, возможно, стоит прокомментировать, что localNotificationScheduleNotification возвращает промис, чтобы была совместимость с асинхронным методом в iOS 10.0+
Или написать тело так (кажется, так чуть понятнее):
return Promise { seal in
guard self.isFireDateValid(contentProvider.fireDate) else {
throw Error.badFireDate
}
// ...
seal.fulfill(())
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ потому что приходится смотреть туда, где этот метод вызывается, так как непонятно, зачем там синхронный код обернут в промис
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да, для разных версий системы разное апи. Смотри как пытаются добиться единообразия https://stackoverflow.com/a/51052127 ![]()
| nextTriggerDate = nil | ||
| } | ||
|
|
||
| if !self.isFireDateValid(nextTriggerDate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогично, отрицание
| throw Error.badContentProvider | ||
| } | ||
|
|
||
| let nextTriggerDate: Date? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возможно, так понятнее
let nextTriggerDate: Date? = {
switch notificationTrigger {
case let timeIntervalTrigger as UNTimeIntervalNotificationTrigger:
return timeIntervalTrigger.nextTriggerDate()
case let calendarTrigger as UNCalendarNotificationTrigger:
return calendarTrigger.nextTriggerDate()
default:
return nil
}
}()
Задача: #APPS-2165
Описание:
Добавили проверку даты перед планированием нотификации.
Из отызва пользователя: