Closed Babyyoda777 closed 2 years ago
@Babyyoda777 this library does not handle jamat/iqamah times as that is really going to be different per masjid and not something that can be calculated.
Okay understood, jazakallah. Then what about notifications. I cannot figure out how to make it work. Here is my implementation:` let cal = Calendar(identifier: Calendar.Identifier.gregorian) let coordinates = Coordinates(latitude: 51.5806, longitude: 0.3420) let size = UIScreen.main.bounds
@State var sunrize : String
@State var fajr : String
@State var dhuhr : String
@State var asr : String
@State var maghrib : String
@State var isha : String
@State var currentPrayer : String
@StateObject var feedViewModel = FeedViewModel()
func calculateTime()->Void{
let date = cal.dateComponents([.year, .month, .day], from: Date())
var params = CalculationMethod.moonsightingCommittee.params
params.madhab = .hanafi
params.adjustments.fajr = 5/2
params.adjustments.sunrise = 2
params.adjustments.dhuhr = 3
params.adjustments.maghrib = -1
params.adjustments.asr = 3
params.adjustments.isha = 3
if let prayers = PrayerTimes(coordinates: coordinates, date: date, calculationParameters: params) {
let formatter = DateFormatter()
formatter.timeStyle = .short
formatter.timeZone = TimeZone(identifier: "Europe/London")!
self.sunrize = formatter.string(from: prayers.sunrise)
self.fajr = formatter.string(from: prayers.fajr)
self.dhuhr = formatter.string(from: prayers.dhuhr)
self.asr = formatter.string(from: prayers.asr)
self.maghrib = formatter.string(from: prayers.maghrib)
self.isha = formatter.string(from: prayers.isha)
}
}`
This is what I have when trying to call a notification but it just says "prayer not found"
let center = UNUserNotificationCenter.current() let content = UNMutableNotificationContent() content.title = "prayer time" content.body = "Time to pray" content.categoryIdentifier = "alarm" content.sound = UNNotificationSound.default let trigger = UNCalendarNotificationTrigger(dateMatching: prayers.fajr, repeats: false) let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) center.add(request)
that's really outside of the scope of this library as well, it's not even clear in this code sample how the notification code gets access to the prayers
struct.
I want to also use the current prayer time feature but I am at loss at how to implement. This is what im trying so far: I get the following error
prayers.currentPrayer
returns a Prayer
value, not a date. You would need to instead use prayers.time(for: prayers.currentPrayer)
to get the Date associated for that Prayer.
Is this what you mean? sorry im still a bit new to swift.
Yes but you will need to unwrap the optional prayer since it can be nil sometimes.
if let currentPrayer = prayers.currentPrayer {
self.current = formatter.string(from: prayers.time(for: currentPrayer))
} else {
// if there's no current prayer then it means its between midnight and fajr.
// It's up to you to decide how you want to handle this situation
}
Hmm, it still gives me a circular reference error :/ as well as Trailing closure passed to parameter of type 'Date' that does not accept a closure
Sorry, currentPrayer is a function. Try this.
if let currentPrayer = prayers.currentPrayer() {
self.current = formatter.string(from: prayers.time(for: currentPrayer))
} else {
// if there's no current prayer then it means its between midnight and fajr.
// It's up to you to decide how you want to handle this situation
}
THANK YOU SO MUCH, YOU HAVE MADE MY DAY. Jazakallah
Sorry for reopening but I this doesn't seem to work no matter what I try :/
Is there a method to control jamat times for each prayer. I am trying to replicate the prayer timing from here: http://harrowmosque.org.uk