batoulapps / adhan-swift

High precision Islamic prayer time library for Swift
MIT License
182 stars 42 forks source link

Prayer times not updating after midnight #87

Closed sabrefm1 closed 1 week ago

sabrefm1 commented 9 months ago

As per the code example provided my method is similar which prints the ahdan values to a uilabel except that I have another function with a uidatepicker to scroll through different dates which in end updates the uilabels specific to that date,

let cal = Calendar(identifier: Calendar.Identifier.gregorian)
let date = cal.dateComponents([.year, .month, .day], from: Date())
let coordinates = Coordinates(latitude: 35.78056, longitude: -78.6389)
var params = CalculationMethod.moonsightingCommittee.params
params.madhab = .hanafi
if let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params) {
let formatter = DateFormatter()
formatter.timeStyle = .medium
formatter.timeZone = TimeZone(identifier: "America/New_York")!

print("fajr \(formatter.string(from: prayers.fajr))")
print("sunrise \(formatter.string(from: prayers.sunrise))")
print("dhuhr \(formatter.string(from: prayers.dhuhr))")
print("asr \(formatter.string(from: prayers.asr))")
print("maghrib \(formatter.string(from: prayers.maghrib))")
print("isha \(formatter.string(from: prayers.isha))")
}

The issue I have at the moment is that the adhan values on the uilabel does not update to the new value after midnight, in fact the solution which works is the close the app and reopen which updates to the current day, any possible solutions?

z3bi commented 1 week ago

You need to observe changes in the date and then manually update the labels. This is not really a part of the library but I would recommend looking at https://developer.apple.com/documentation/uikit/uiapplication/1623059-significanttimechangenotificatio