Skip to content

Conversation

@ivan-magda
Copy link
Member

@ivan-magda ivan-magda commented Dec 10, 2018

Задача: #APPS-2165

Описание:
Добавили проверку даты перед планированием нотификации.
Из отызва пользователя:

При запуске приложения непрерывно выпадают сверху напоминания от всех активных курсов и модулей.

@ivan-magda ivan-magda self-assigned this Dec 10, 2018
@ivan-magda ivan-magda requested review from Ostrenkiy and kvld December 10, 2018 16:25
private func localNotificationScheduleNotification(
contentProvider: LocalNotificationContentProvider
) -> Promise<Void> {
if !self.isFireDateValid(contentProvider.fireDate) {
Copy link
Contributor

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) 
}

Copy link
Contributor

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(())
}

Copy link
Contributor

@kvld kvld Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ потому что приходится смотреть туда, где этот метод вызывается, так как непонятно, зачем там синхронный код обернут в промис

Copy link
Member Author

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 :trollface:

nextTriggerDate = nil
}

if !self.isFireDateValid(nextTriggerDate) {
Copy link
Contributor

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?
Copy link
Contributor

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
    }
}()

@ivan-magda ivan-magda merged commit a03e598 into dev Dec 12, 2018
@ivan-magda ivan-magda deleted the fix/expired-local-notifications-scheduling branch December 12, 2018 16:31
@kvld kvld added this to the 1.74 milestone Dec 13, 2018
@kvld kvld mentioned this pull request Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants