【发布时间】:2016-11-10 05:45:46
【问题描述】:
我是 iOS 开发的新手,但已经创建了应用程序,并且我正在尝试为特定时间(例如(上午 10 点))创建每日通知。如果我将移动设备时间设置为上午 10 点,现在通知会太多。我只想在给定的特定时间(即上午 10 点)触发一次本地通知,并且我想每天重复一次。每天重复通知的最佳方法是什么?
这是我的代码
func fire(){
let dateComp:NSDateComponents = NSDateComponents()
dateComp.hour = 10
dateComp.minute = 00
dateComp.timeZone = NSTimeZone.systemTimeZone()
let calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierIndian)!
let date:NSDate = calender.dateFromComponents(dateComp)!
let localNotificationSilent = UILocalNotification()
localNotificationSilent.fireDate = date
localNotificationSilent.repeatInterval = NSCalendarUnit.Day
localNotificationSilent.alertBody = "Started!"
localNotificationSilent.alertAction = "swipe to hear!"
localNotificationSilent.timeZone = NSCalendar.currentCalendar().timeZone
localNotificationSilent.category = "PLAY_CATEGORY"
UIApplication.sharedApplication().scheduleLocalNotification(localNotificationSilent)
}
【问题讨论】:
标签: ios iphone swift uilocalnotification nscalendar