Если заявление с использованием локального уведомления - PullRequest
0 голосов
/ 28 апреля 2020

Могу ли я использовать локальное уведомление в операторе if? Или есть лучшее решение? Этот код имеет ошибку индекса таблицы ошибок:

extension ViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return results.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "ResultCell")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "ResultCell")
        }

        let result = results[indexPath.row]

        let label = convert(id: result.label)
        cell!.textLabel!.text = "\(label): \(result.confidence)"



        if convert(id: result.label) == "metro" && result.confidence >= 10{
            let content = UNMutableNotificationContent()

            content.title = "Sound helper"
            content.subtitle = "metro"
            content.badge = 1
            //2. Use TimeIntervalNotificationTrigger
            let TimeIntervalTrigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)
            let request = UNNotificationRequest(identifier: "\(String(describing: index))timerdone", content: content, trigger: TimeIntervalTrigger)
            UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
        }

    private func convert(id: String) -> String {
        let mapping = ["carhorn" : "carhorn", "dog" : "dog", "fire" : "fire",
                       "glass" : "glass", "metro" : "metro",
                       "policeSiren" : "policeSiren","humanVoice":"humanVoice"]
        return mapping[id] ?? id
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...