【发布时间】:2020-01-31 05:35:59
【问题描述】:
请帮忙
用户通知
Import UserNotifications
把它放在 viewDidLoad 中
func setupNotif() {
UNUserNotificationCenter.current().requestAuthorization(options [.alert,.sound]) {
(granted, error) in
}
let notificationContent = UNMutableNotificationContent()
notificationContent.title = "Push Invitation"
notificationContent.subtitle = "Push subtitle"
notificationContent.body = "Please check notif"
notificationContent.sound = .default
notificationContent.categoryIdentifier = categoryIdentifier
let notificationTrigger = UNTimeIntervalNotificationTrigger.init(timeInterval: timeInterval, repeats: false)
let notificationRequest = UNNotificationRequest.init(identifier: "SampleNotif", content: notificationContent, trigger: notificationTrigger)
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
UNUserNotificationCenter.current().add(notificationRequest) {(error) in if (error != nil) {} else { }}
}
这是 UUNotification 中心的代表
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
}
【问题讨论】:
-
let action1 = UNNotificationAction(identifier: "tapAction1",title: "Tap me later", options: [.init(rawValue: 0)]) let action2 = UNNotificationAction(identifier: "tapAction1", title: "Tap me now", options: [.foreground]) let action3 = UNNotificationAction(identifier: "decline", title: "Decline", options: [])
-
请编辑您的问题并更好地描述您的问题,以便人们可以帮助您。
-
@Hassan,标题说明了一切......我需要小部件来捕捉推送通知操作......它只在应用程序上工作......
标签: swift push-notification widget