自定义操作未出现在推送通知中

时间:2019-10-04 18:10:35

标签: ios swift push-notification

我向左滑动通知时的操作未如图所示,我只能通过按“查看”按钮来访问该操作 Screen grab

Link to the above screen grab

if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self as! UNUserNotificationCenterDelegate
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
                options: authOptions,
                completionHandler: {_, _ in })

            // For iOS 10 data message (sent via FCM)
            Messaging.messaging().delegate = self
            Messaging.messaging().isAutoInitEnabled = true
        } else {


            let completeAction = UIMutableUserNotificationAction()
            completeAction.identifier = "COMPLETE_TODO" // the unique identifier for this action
            completeAction.title = "Complete" // title for the action button
            completeAction.activationMode = .background // UIUserNotificationActivationMode.Background - don't bring app to foreground
            completeAction.isAuthenticationRequired = false // don't require unlocking before performing action
            completeAction.isDestructive = true // display action in red

            let remindAction = UIMutableUserNotificationAction()
            remindAction.identifier = "REMIND"
            remindAction.title = "Remind in 30 minutes"
            remindAction.activationMode = .background
            remindAction.isDestructive = false

            let todoCategory = UIMutableUserNotificationCategory() // notification categories allow us to create groups of actions that we can associate with a notification
            todoCategory.identifier = "TODO_CATEGORY"
            todoCategory.setActions([remindAction, completeAction], for: .default) // UIUserNotificationActionContext.Default (4 actions max)
            todoCategory.setActions([completeAction, remindAction], for: .minimal) // UIUserNotificationA


            let settings: UIUserNotificationSettings =
                UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: Set([todoCategory]))

            application.registerUserNotificationSettings(settings)
        }

0 个答案:

没有答案