我想每天发送三次推送通知。哪个应该在每个通知中显示各种时间数据。作为示例,它应该给出当它发射减去常数时的当前时间。我知道你可以像这样设置起火日期:
notification.repeatInterval = NSCalendar.Unit.hour
但是我如何设置alertbody变量?
感谢。
答案 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)