iOS本地通知缺少操作按钮

时间:2017-11-16 17:57:48

标签: ios swift usernotifications

我正在制作我的第一个应用程序而且我可能面临的最大问题就在于它。我试图用for循环重复本地通知,每个都有不同的类别,但由于某种原因它不起作用。我实际上得到了所有的通知,但是当我向下看通知时看到我没有看到任何动作的动作。你遇到过这种问题,如果你做了,你是怎么设法解决的?我是通知试图制作的是重复今天安排的本地通知。

这是我的代码:

for index in 0..<workingDays[3].subjects!.count {
    howManyLeft -= 1
    var seperated = workingDays[3].subjects![index].endsAt!.components(separatedBy: ":")
    var dateComponents = DateComponents()
    dateComponents.hour = Int(seperated[0])
    dateComponents.minute = Int(seperated[1])
    dateComponents.weekday = 5

    // make category
    let actionBaby = UNNotificationAction(identifier: "oneaction\(index)", title: "something\(index)", options: .foreground)
    let category = UNNotificationCategory(identifier: "\(index).5", actions: [actionBaby], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: "idk", options: [])
    UNUserNotificationCenter.current().setNotificationCategories([category])

    // If contition is true make notification
    if index + 1 >= 0 && index + 1 < workingDays[3].subjects!.count {
        let notification = UNMutableNotificationContent()
        notification.categoryIdentifier = "\(index).5"
        notification.title = "someRandom\(index)"
        let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
        let request = UNNotificationRequest(identifier: "\(index)5",
            content: notification,
            trigger: trigger)
        UNUserNotificationCenter.current().add(request)
    }
}

0 个答案:

没有答案