-
Notifications
You must be signed in to change notification settings - Fork 34
Fix streak notifications scheduling for iOS 10.0* #430
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,23 @@ import Foundation | |
| import UserNotifications | ||
|
|
||
| final class StreakLocalNotificationContentProvider: LocalNotificationContentProvider { | ||
| private let UTCStartHour: Int | ||
| private let calendar: Calendar | ||
|
|
||
| private var dateComponents: DateComponents { | ||
| let timeZoneDiff = NSTimeZone.system.secondsFromGMT() / 3600 | ||
| var localStartHour = self.UTCStartHour + timeZoneDiff | ||
|
|
||
| if localStartHour < 0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не по теме ПРа, но каждый раз смотрю на этот кусок кода и не понимаю, почему вообще в пикере происходит какое-то шаманство с датой. Ведь можно же оттуда отдавать DateComponents с выбранным часом сразу
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я не разбирался, возможно @Ostrenkiy помнит, почему пришлось шаманить.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кажется, там шаманство из-за того, что в пикере дата должна быть в локальном часовом поясе, а сохраняем ее мы в UTC формате. |
||
| localStartHour = 24 + localStartHour | ||
| } | ||
| if localStartHour > 23 { | ||
| localStartHour = localStartHour - 24 | ||
| } | ||
|
|
||
| return DateComponents(hour: localStartHour) | ||
| } | ||
|
|
||
| var title = "" | ||
|
|
||
| var body: String { | ||
|
|
@@ -52,33 +69,6 @@ final class StreakLocalNotificationContentProvider: LocalNotificationContentProv | |
| return UNCalendarNotificationTrigger(dateMatching: self.dateComponents, repeats: true) | ||
| } | ||
|
|
||
| private let UTCStartHour: Int | ||
| private let calendar: Calendar | ||
|
|
||
| private var dateComponents: DateComponents { | ||
| let timeZoneDiff = NSTimeZone.system.secondsFromGMT() / 3600 | ||
| var localStartHour = self.UTCStartHour + timeZoneDiff | ||
|
|
||
| if localStartHour < 0 { | ||
| localStartHour = 24 + localStartHour | ||
| } | ||
| if localStartHour > 23 { | ||
| localStartHour = localStartHour - 24 | ||
| } | ||
|
|
||
| let currentDate = Date() | ||
|
|
||
| var components = DateComponents() | ||
| components.year = self.calendar.component(.year, from: currentDate) | ||
| components.month = self.calendar.component(.month, from: currentDate) | ||
| components.day = self.calendar.component(.day, from: currentDate) | ||
| components.hour = localStartHour | ||
| components.minute = 0 | ||
| components.second = 0 | ||
|
|
||
| return components | ||
| } | ||
|
|
||
| init(UTCStartHour: Int, calendar: Calendar = Calendar(identifier: .gregorian)) { | ||
| self.UTCStartHour = UTCStartHour | ||
| self.calendar = calendar | ||
|
|
||
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.
Тут кстати вроде как есть bridge в TimeZone