【问题标题】:Schedule iOS Local Push Notification安排 iOS 本地推送通知
【发布时间】:2018-08-08 07:42:14
【问题描述】:
let center = UNUserNotificationCenter.current()
let options: UNAuthorizationOptions = [.alert, .sound];
center.requestAuthorization(options: options) { (granted, error) in
    if !granted {
        print("Something went wrong")
    }
}
center.getNotificationSettings { (settings) in
    if settings.authorizationStatus != .authorized {
        // Notifications not allowed
    }
}
let content = UNMutableNotificationContent()
content.title = "Good Morning"
content.body = "wake up"
content.sound = UNNotificationSound.default()
var dateInfo = DateComponents()
dateInfo.hour = 7
dateInfo.minute = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: dateInfo, repeats: true)
let identifier = "localNotification"
let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
center.add(request, withCompletionHandler: { (error) in
    if let _ = error {
        LOGG("Something went wrong")
    }
})

以上代码,早上 7 点完美触发推送通知。我如何使用相同的代码在晚上 9 点或 12 点设置通知。谢谢。

【问题讨论】:

    标签: ios swift push-notification ios10 uilocalnotification


    【解决方案1】:

    尝试在晚上 9 点开火

        var dateInfo = DateComponents()
        dateInfo.hour = 21
        dateInfo.minute = 0
    

    【讨论】:

    • 表示 'DateComponents' 以 24 小时格式工作,让我试试,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多