栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

无论启动日期如何,只要加载应用,UILocalNotification就会始终显示

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

无论启动日期如何,只要加载应用,UILocalNotification就会始终显示

更新: Xpre 7.1•Swift 2.1

问题是您将日期组件设置为localTime区域而不是通知。

添加此扩展NSDate以从NSDate()返回所需的组件

extension NSDate {    var minute: Int { return NSCalendar.currentCalendar().component(.Minute, fromDate: self)}    var hour:   Int { return NSCalendar.currentCalendar().component(.Hour,   fromDate: self)}    var day:    Int { return NSCalendar.currentCalendar().component(.Day,    fromDate: self)}    var month:  Int { return NSCalendar.currentCalendar().component(.Month,  fromDate: self)}    var year:   Int { return NSCalendar.currentCalendar().component(.Year,   fromDate: self)}    func fireDateAt(hr: Int, min: Int) -> NSDate {        let date = NSDate()        return NSCalendar.currentCalendar().dateWithEra(1, year: year, month: month, day: { hr > date.hour || (hr == date.hour && min > date.minute) ? day : day + 1 }(), hour: hr, minute: min, second: 0, nanosecond: 0        )!    }}

timeZone属性

通知生效日期的时区。

fireDate中指定的日期根据该属性的值进行解释。如果指定nil(默认值),则触发日期将解释为绝对GMT时间,适用于诸如倒数计时器的情况。如果为该属性分配有效的NSTimeZone对象,则触发日期将被解释为挂钟时间,该时区会在时区发生更改时自动调整;一个适合这种情况的例子是闹钟。

func prayeralert (prayerName : String, prayHour : Int, prayMinute : Int) {    var notification = UILocalNotification()    notification.timeZone  = NSTimeZone.localTimeZone()    notification.alertBody = prayerName    notification.fireDate  = NSDate().fireDateAt(prayHour, min: prayMinute)    UIApplication.sharedApplication().scheduleLocalNotification(notification)}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382496.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号