每天在设定的时间与swift重复本地通知

编程入门 行业动态 更新时间:2024-10-27 15:16:17
本文介绍了每天在设定的时间与swift重复本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是iOS开发的新手,但是已经创建了应用程序,我试图在设定的时间内创建每日通知。目前,通知对于给定的日期/时间执行一次。我不确定如何使用repeatInterval方法来每天安排。每天重复通知的最佳方法是什么?任何帮助将非常感谢(Y)。

var dateComp:NSDateComponents = NSDateComponents() dateComp.year = 2015; dateComp.month = 06; dateComp.day = 03; dateComp.hour = 12; dateComp.minute = 55; dateComp.timeZone = NSTimeZone.systemTimeZone() var calender:NSCalendar = NSCalendar(calendarIdentifier:NSCalendarIdentifierGregorian)! var date:NSDate = calender.dateFromComponents(dateComp)! var notification:UILocalNotification = UILocalNotification() notification.category =Daily Quote notification.alertBody = quoteBook.randomQuote() notification.fireDate = date notification.repeatInterval = UIApplication.sharedApplication()。scheduleLocalNotification(notification)

。您必须提供NSCalendarUnit值,例如HourCalendarUnit或DayCalendarUnit才能重复通知。

只需添加此代码即可每天重复本地通知:

notification.repeatInterval = NSCalendarUnit.CalendarUnitDay

I am new to iOS development, but have created the app and I am trying to create a daily notification for a set time. Currently the notification executes once for the given date/time. I am unsure how to use the repeatInterval method to schedule it daily. What is the best method to repeat the notification daily ? any help would be much appreciated (Y).

var dateComp:NSDateComponents = NSDateComponents() dateComp.year = 2015; dateComp.month = 06; dateComp.day = 03; dateComp.hour = 12; dateComp.minute = 55; dateComp.timeZone = NSTimeZone.systemTimeZone() var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)! var date:NSDate = calender.dateFromComponents(dateComp)! var notification:UILocalNotification = UILocalNotification() notification.category = "Daily Quote" notification.alertBody = quoteBook.randomQuote() notification.fireDate = date notification.repeatInterval = UIApplication.sharedApplication().scheduleLocalNotification(notification)

解决方案

You have to provide an NSCalendarUnit value like "HourCalendarUnit" or "DayCalendarUnit" for repeating a notification.

Just add this code to repeat the local notification daily :

notification.repeatInterval = NSCalendarUnit.CalendarUnitDay

更多推荐

每天在设定的时间与swift重复本地通知

本文发布于:2023-11-27 02:49:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636255.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   时间   swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!