显示本地推送通知,除非用户点击它

时间:2018-06-29 14:13:05

标签: ios swift

这是我创建本地通知的方法,该通知会在3秒后成功显示

let content = UNMutableNotificationContent()
    content.title = "Test"
    content.body = "Test"
    content.categoryIdentifier = "UYLReminderCategory"
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3,
                                                    repeats: false)
    let identifier = "UYLLocalNotification"
    let request = UNNotificationRequest(identifier: identifier,
                                        content: content, trigger: trigger)
    let snoozeAction = UNNotificationAction(identifier: "Snooze",
                                            title: "Snooze", options: [])
    let deleteAction = UNNotificationAction(identifier: "UYLDeleteAction",
                                            title: "Delete", options: [.destructive])
    let category = UNNotificationCategory(identifier: "UYLReminderCategory",
                                          actions: [snoozeAction,deleteAction],
                                          intentIdentifiers: [], options: [])
    center.setNotificationCategories([category])

    center.add(request, withCompletionHandler: { (error) in
        if let error = error {
            // Something went wrong
        }
    })

,但是它会在几秒钟后隐藏起来,是否有可能防止它隐藏起来,就像在“警报”应用程序中内置的苹果一样。 谢谢。

1 个答案:

答案 0 :(得分:3)

通知的行为由系统控制,您的应用无法覆盖它。
用户is in control来显示应用程序的通知。

Image from Apple's user support page
Apple用户支持的图片page