如何在swift中安排相同的本地通知 [英] How to schedule a same local notification in swift

查看:96
本文介绍了如何在swift中安排相同的本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在Swift中安排相同的本地通知。例如,我只想安排一条消息,说现在是时候计算本月的账单了,我想在下个月再次发送同样的消息。

I just want to schedule a same local notification in Swift. For example I just want to schedule a message saying "It's time to calculate your bill for this month" and I want to send this same message again next month.

如何在Swift中进行这种本地通知?

How to do this kind of local notification in Swift?

我引用了以下内容,但未能在下个月安排相同的消息......

I have referenced followings but was not able to schedule a same message in next month ...

// http://thecodeninja.tumblr.com/post/89942124085/notifications-in-ios-8-part-1-using-swift-what-is
// < a href =https://stackoverflow.com/questions/25686284/from-string-to-nsdate-in-swift>从Swift中的字符串到NSDate

推荐答案

UILocalNotification 有一个 repeatInterval 属性,可让您指定方式通常应该重复通知。请注意,这是 NSCalendarUnit ,而不仅仅是一个任意数字,因此您只能在每个日历单位(第二,分钟,小时,日,周,月)重复通知一次等)。请参阅 NSCalendarUnit 文档了解更多选项。

UILocalNotification has a repeatInterval property that lets you specify how often the notification should repeat. Note that this is an NSCalendarUnit, not just an arbitrary number, so you can only make a notification repeat once per calendar unit (second, minute, hour, day, week, month, etc.). See the NSCalendarUnit documentation for more options.

例如,您可以每月重复通知:

For example, you can make a notification repeat every month with:

notification.repeatInterval = .CalendarUnitMonth

这篇关于如何在swift中安排相同的本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆