【问题标题】:How To Create Alarm Notification Swift iOS?如何创建警报通知 Swift iOS?
【发布时间】:2021-02-24 09:23:11
【问题描述】:

当用户从 fcm(Firebase 云消息传递)或调度程序本地通知(如下图所示的警报通知)收到通知时,我想这样做:

这是我的代码:


func onTest() {
      
        let content = UNMutableNotificationContent()
        content.title = "Weekly Staff Meeting"
        content.body = "Every Tuesday at 2pm"
        // Configure the recurring date.
        var dateComponents = DateComponents()
        dateComponents.calendar = Calendar.current

        dateComponents.hour = 16    // 14:00 hours
        dateComponents.minute = 11
           
        // Create the trigger as a repeating event.
        let trigger = UNCalendarNotificationTrigger(
                 dateMatching: dateComponents, repeats: true)
        
        // Create the request
        let uuidString = UUID().uuidString
        let request = UNNotificationRequest(identifier: uuidString,
                    content: content, trigger: trigger)

        // Schedule the request with the system.
        let notificationCenter = UNUserNotificationCenter.current()
        notificationCenter.add(request) { (error) in
           if error != nil {
              // Handle any errors.
           }
        }
    } 

我现在的代码就像在 5 秒内消失的通常通知一样,我想让它像警报通知或 Whatsapp 呼叫通知一样。请帮忙谢谢。

【问题讨论】:

    标签: ios swift push-notification notifications alarm


    【解决方案1】:

    由于 Apple 的限制,app dev 最多只能播放 30 秒的通知音。如果您的提示音超过 30 秒,它将播放默认通知音。

    如果您的通知音在 5 秒后消失,请尝试将您的通知演示选项设置为列表、徽章和声音。 一旦没有通知横幅,您的 30 秒提示音将一直播放到结束。

    不幸的是,没有合法的方式或任何解决方法可以让通知响铃连续响起,例如闹钟。希望我错了。

    https://developer.apple.com/documentation/usernotifications/unnotificationpresentationoptions

    【讨论】:

      【解决方案2】:

      我认为,您最多只能提供本地通知。但是,是的,这与 Apple 警报通知不完全一样。在现实中,您无权执行此操作。您只能呈现本地通知。

      【讨论】:

      • 问题是我创建的通知仅在 5 秒后消失,我想将其设置为警报通知,这意味着当我们单击该通知时警报将消失。
      • 无论是 FCM 还是本地通知,它都会消失 5 秒兄弟。
      • 但是没有别的办法。您不能使本地通知永久显示。但是,您的通知将始终显示在通知屏幕上。
      • 如果想永久保存我该怎么办?
      • 任何链接教程或关键字。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      相关资源
      最近更新 更多