本地推送通知是否可以包含可变内容?

时间:2018-03-01 10:29:56

标签: ios swift push-notification apple-push-notifications

我想每天发送三次推送通知。哪个应该在每个通知中显示各种时间数据。作为示例,它应该给出当它发射减去常数时的当前时间。我知道你可以像这样设置起火日期:

 notification.repeatInterval = NSCalendar.Unit.hour

但是我如何设置alertbody变量?

感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用UNMutableNotificationContent类并使用title属性设置标题文本,使用body设置通知正文文本。对于例如

let content = UNMutableNotificationContent()
content.title = NSString.localizedUserNotificationString(forKey: "Wake up!", arguments: nil)
content.body = NSString.localizedUserNotificationString(forKey: "Rise and shine! It's morning time!",
                                                        arguments: nil)

// Configure the trigger for a 7am wakeup.
var dateInfo = DateComponents()
dateInfo.hour = 7
dateInfo.minute = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: false)

// Create the request object.
let request = UNNotificationRequest(identifier: "MorningAlarm", content: content, trigger: trigger)