如何在一段时间后自动隐藏通知并在 Swift 中播放铃声?

问题描述

我能够成功显示通知,但遇到了两个问题:

  1. 我想播放铃声而不是播放通知声音。
  2. 如果用户在 30 秒内没有执行任何操作,我还想隐藏通知
let content = UNMutableNotificationContent()
content.title = "Incoming Call"
content.subtitle = "Call from a user XYZ"
content.sound = UNNotificationSound.default

// show this notification five seconds from now
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5,repeats: false)

// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString,content: content,trigger: trigger)

// add our notification request
UNUserNotificationCenter.current().add(request)

我尝试了 stackoverflow 中的一些解决方案,但像 notif.soundName = UILocalNotificationDefaultSoundName;

那样对我不起作用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...