如何通过排除今天来安排IOS UserNotification

时间:2018-04-06 14:04:02

标签: ios swift notifications

我想在通知注册后一天向我的iOS应用程序用户发送通知。换句话说,我想在UNUserNotificationCenter中排除通知注册的日期(我希望从明天开始每天发送通知)。

    var dateInfo = DateComponents()
    dateInfo.hour = 12
    dateInfo.minute = 30
    let content = UNMutableNotificationContent()
    content.title = NSString.localizedUserNotificationString(forKey: "daily notification:", arguments: nil)
    content.body = NSString.localizedUserNotificationString(forKey: "Hello !Get up,", arguments: nil)
    content.sound = UNNotificationSound.default()
    content.badge = UIApplication.shared.applicationIconBadgeNumber + 1 as NSNumber;
    content.categoryIdentifier = "Daily notification"
    // Deliver the notification every day at 12:30 am.
    let trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: false)
    let request = UNNotificationRequest.init(identifier: "midnoonHalfNotification", content: content, trigger: trigger)

1 个答案:

答案 0 :(得分:0)

计算现在(创建请求时)和明天12:30之间的时间间隔,并使用UNTimeIntervalNotificationTrigger作为触发器,使用计算的间隔而不是日历触发器。