Ios 两种不同类别的本地通知

Ios 两种不同类别的本地通知,ios,swift,xcode,swift3,notifications,Ios,Swift,Xcode,Swift3,Notifications,我创建了两个不同的函数,每个函数创建一个新的本地通知 func scheduleLocalNotification() { // Create Notification Content let notificationContent = UNMutableNotificationContent() // Configure Notification Content notificationContent.title = "Notif 1" noti

我创建了两个不同的函数,每个函数创建一个新的本地通知

   func scheduleLocalNotification() {
    // Create Notification Content
    let notificationContent = UNMutableNotificationContent()

    // Configure Notification Content
    notificationContent.title = "Notif 1"
    notificationContent.subtitle = "Local Notifications"
    notificationContent.body = "hellow worlds."

    // Set Category Identifier
    notificationContent.categoryIdentifier = Notification.Category.tutorial

    // Add Trigger
    let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)

    // Create Notification Request
    let notificationRequest = UNNotificationRequest(identifier: "cocoacasts_local_notification", content: notificationContent, trigger: notificationTrigger)

    // Add Request to User Notification Center
    UNUserNotificationCenter.current().add(notificationRequest) { (error) in
        if let error = error {
            print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
        }
    }
}
func scheduleLocalNotification2() {
    // Create Notification Content
    let notificationContent = UNMutableNotificationContent()

    // Configure Notification Content
    notificationContent.title = "Notif 2"
    notificationContent.subtitle = "Local Notifications"
    notificationContent.body = "hellow world + snooze"

    // Set Category Identifier
    notificationContent.categoryIdentifier = Notification.Category.tutorial

    // Add Trigger
    let notificationTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 10.0, repeats: false)

    // Create Notification Request
    let notificationRequest = UNNotificationRequest(identifier: "cocoacasts_local_notification", content: notificationContent, trigger: notificationTrigger)

    // Add Request to User Notification Center
    UNUserNotificationCenter.current().add(notificationRequest) { (error) in
        if let error = error {
            print("Unable to Add Notification Request (\(error), \(error.localizedDescription))")
        }
    }
}
我想让第一个函数创建一个没有任何操作的普通通知,第二个函数创建一个带有操作按钮的通知。所以我创建了以下函数

func configureUserNotificationsCenter() {
    // Configure User Notification Center
    UNUserNotificationCenter.current().delegate = self

    // Define Actions
    let actionReadLater = UNNotificationAction(identifier: Notification.Action.readLater, title: "Read Later", options: [])
    let actionShowDetails = UNNotificationAction(identifier: Notification.Action.showDetails, title: "Show Details", options: [.foreground])
    let actionUnsubscribe = UNNotificationAction(identifier: Notification.Action.unsubscribe, title: "Unsubscribe", options: [.destructive, .authenticationRequired])

    // Define Category
    let tutorialCategory = UNNotificationCategory(identifier: Notification.Category.tutorial, actions: [actionReadLater, actionShowDetails, actionUnsubscribe], intentIdentifiers: [], options: [])

    // Register Category
    UNUserNotificationCenter.current().setNotificationCategories([tutorialCategory])
}

然后,我在viewdidload中调用configureUserNotificationsCenter,但这会导致我的所有通知都有这些操作按钮。我只希望使用scheduleLocalNotifications2函数调度的通知,其他函数的通知不应具有这些操作按钮。我该怎么做呢?

这两种方法都使用了
通知.Category.tutorial的
通知内容.categoryIdentifier
。这是指定按钮所在的同一类别,这就是为什么它同时显示在这两个类别上。您需要为通知创建第二个类别标识符,不带按钮