0
我正在使用cvcalendar,每天有不同的時間爲fajer,dohor,aser,maghreb,ishaa。例如我選擇了Adan for Fajer,所以我想在日常生活中每天都有adan,每天都有不同的時間。所以當我在DidreceivedLocalNotification中收到通知時,我希望在日曆中的第二天獲得第二天的時間,知道是從CoreData獲取時間。如何根據CVcalendar中的特定時間進行每日本地通知?
在viewWillAppear中 let date = NSDate()
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
let calendar = NSCalendar.currentCalendar()
let calendarForDate = NSCalendar.currentCalendar()
let componentsForDate = calendar.components([.Day , .Month , .Year], fromDate: date)
let year = componentsForDate.year
let month = componentsForDate.month
let day = componentsForDate.day
//////////
//// Conditions after selecting the user (vibration, beep, Adan) these conditions are testing the selected choice to send a notification to the user on his choice
//
if prayerCommingFromAdan.id == 0 && prayerCommingFromAdan.ringToneId != 0{
notificationId.id = 0
let hours = prayer0.time[0...1]
let minutes = prayer0.time[3...4]
let fajerTime = "\(month)-\(day)-\(year) \(hours):\(minutes)"
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "MM-dd-yyyy hh:mm"
dateFormatter.timeZone = NSTimeZone.localTimeZone()
// convert string into date
let dateValue = dateFormatter.dateFromString(fajerTime) as NSDate!
var dateComparisionResult:NSComparisonResult = NSDate().compare(dateValue)
if dateComparisionResult == NSComparisonResult.OrderedAscending
{
addNotificationAlarm(year, month: month, day: day, hour: prayer0.time[0...1], minutes: prayer0.time[3...4], soundId: prayerCommingFromAdan.ringToneId, notificationBody: "It is al fajr adan")
}
我應該在DidreceivedLocalNotification做什麼的AppDelegate
?
阿南德謝謝你,但我的問題是如何讓時間第二天日曆以及如何在AppDelegate中使用DidreceivedLocalNotification? –
我在答案中添加了接收代碼。請檢查一下。 –
您可以使用NSDate手動設置時間以設置本地通知。 –