Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS本地通知缺少操作按钮_Ios_Swift_Usernotifications - Fatal编程技术网

iOS本地通知缺少操作按钮

iOS本地通知缺少操作按钮,ios,swift,usernotifications,Ios,Swift,Usernotifications,我刚刚制作了我的第一个应用程序,我可能正面临着其中最大的问题。我尝试使用for循环重复本地通知,每个通知都有不同的类别,但由于某种原因,它不起作用。我实际上收到了所有的通知,但当我打开通知查看操作时,我看不到任何操作。您是否曾经遇到过此类问题?如果您遇到了,您是如何解决的?我尝试发出的通知是重复计划在今天发出的本地通知 这是我的密码: for index in 0..<workingDays[3].subjects!.count { howManyLeft -= 1 var

我刚刚制作了我的第一个应用程序,我可能正面临着其中最大的问题。我尝试使用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..=0&&index+1中的索引
更具体一些。“它不起作用”没有任何意义。您是否遇到运行时/编译时错误?如果没有,预期的行为是什么,实际的行为是什么?我的错,很抱歉,我实际上收到了所有通知,但当我下拉通知查看操作时,我看不到任何操作。值得一提的是,For循环似乎是一种非常脆弱的方法。考虑使用结构或类来保存通知和它们的动作,而不是使用迭代器。我不明白,如何使用Strut来实现这一点呢?你能给我举一个结构的例子吗?我是初学者,像你这样一次又一次地创建同一个类别是疯狂的。尝试一下:不要在创建通知请求的同时设置类别。您应该在很久以前设置过一次类别,例如在
应用程序中设置过一次。类别是长期存在的永久对象。