带有动态警报正文的Swift本地通知

所以我可以创建这样的本地通知

var localNotification = UILocalNotification() localNotification.fireDate = NSDate(timeIntervalSinceNow: 7) localNotification.alertBody = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .MediumStyle, timeStyle: .ShortStyle) localNotification.timeZone = NSTimeZone.defaultTimeZone() localNotification.repeatInterval = NSCalendarUnit.CalendarUnitMinute UIApplication.sharedApplication().scheduleLocalNotification(localNotification) 

这会立即创建一个带日期的通知,然后开始每分钟关闭一次永恒。 如果创建通知的时间是下午5点,那么每次发射时都会说下午5点,即使30分钟后时间是5:30。

我需要做些什么来使警报体动态化?

我在文档中读到它需要一个alertBody字符串,所以我无法弄清楚如何设置带有函数调用或时间戳或更改值的消息体。

https://developer.apple.com/library/ios/documentation/iPhone/Reference/UILocalNotification_Class/#//apple_ref/occ/instp/UILocalNotification/alertBody

基本上我希望我的应用程序在通知即将触发时计算值,而不是在设置时计算,以创建消息。 关于使用每分钟通知的例子,以便您可以看到此代码的实际效果。 在真实的应用程序中,我想在预定的时间发出每日通知。 EG每天早上7点开始计算一次当时的值。

你不能让它变得动态。 对于每个单独的时间,您需要单独的通知和单独的文本。