自定义本地推送通知

时间:2018-11-20 05:29:47

标签: swift xcode push-notification actionable-notification

我已经成功设置了本地推送通知,提醒人们起床并锻炼腿部,但是我遇到了一些问题:

1)显示而不是隐藏推送通知的操作。选项在那里,但默认情况下只是隐藏的,因此我需要向下滑动才能看到选项。这与3Touch业务有关吗?我正在IOS 12.1上运行该应用程序。

2)有没有办法进行设置,以便仅在上午9点至下午5点之间触发通知(不会在凌晨3点叫醒别人,是吗?)?

谢谢大家!

func sendNotification() {
    let content = UNMutableNotificationContent()
    content.title = "Reminder"
    content.subtitle = "From Snap!"
    content.body = "It's LEG EXERCISE Time!"
    content.categoryIdentifier = "actionCategory"
    content.badge = 0
    content.sound = UNNotificationSound.default()

    let okayAction = UNNotificationAction(identifier:"Okay", title:"Okay",options:[])
    let category = UNNotificationCategory(identifier: "actionCategory", actions: [okayAction], intentIdentifiers: [], options: [])

    UNUserNotificationCenter.current().setNotificationCategories([category])

    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3600, repeats: true)
    let requestIdentifier = "StandupNotification"
    let request = UNNotificationRequest(identifier: requestIdentifier, content: content, trigger: trigger)
    UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in
                                            // Handle error
    })
}

0 个答案:

没有答案
相关问题