自定义通知界面

时间:2019-03-13 07:39:00

标签: ios swift push-notification

我正在定制远程通知UI上,要在其中添加4 UNNotificationAction。 我已经完成了实施,并且在 iPhone 5 以外的所有设备上都能正常工作。在iPhone 5上,它仅显示前2个动作和“清除”动作,这是默认动作。

在iPhone 5上也不会调用内容扩展和服务扩展中的代码。

下面是我的代码段。

func setCategories(){
        //Actions
        let remindLaterAction = UNNotificationAction(identifier: "remindLater", title: "Remind me later", options: UNNotificationActionOptions(rawValue: 0))
        let acceptAction = UNNotificationAction(identifier: "accept", title: "Accept", options: .foreground)
        let declineAction = UNNotificationAction(identifier: "decline", title: "Decline", options: .destructive)
        let commentAction = UNTextInputNotificationAction(identifier: "comment", title: "Comment", options: .authenticationRequired, textInputButtonTitle: "Send", textInputPlaceholder: "Share your thoughts..")

        //Category
        let invitationCategory = UNNotificationCategory(identifier: "alarm.category", actions: [remindLaterAction, acceptAction, declineAction, commentAction], intentIdentifiers: [], options: UNNotificationCategoryOptions(rawValue: 0))

        //Register the app’s notification types and the custom actions that they support.
        UNUserNotificationCenter.current().setNotificationCategories([invitationCategory])
    }

与设备或操作系统有关吗?

0 个答案:

没有答案