ios – 本地通知发出声音但不显示(Swift)

ios – 本地通知发出声音但不显示(Swift),第1张

概述我正在尝试使用Apple的UNUserNotificationCenter为我的应用创建本地通知. 这是我的代码: let center = UNUserNotificationCenter.current()let content = UNMutableNotificationContent()content.title = task.namecontent.body = task.no 我正在尝试使用Apple的UNUserNotificationCenter为我的应用创建本地通知.

这是我的代码:

let center = UNUserNotificationCenter.current()let content = UNMutableNotificationContent()content.Title = task.namecontent.body = task.notescontent.sound = UNNotificationSound.default()let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5,repeats: false)let request = UNNotificationRequest(IDentifIEr: task.UUID,content: content,trigger: trigger)center.add(request) { (error:Error?) in   if let theError = error {      print("Notification scheduling error: \(error)")   }else{      print("Notification was scheduled successfully")   }}

访问请求:

let center = UNUserNotificationCenter.current()//request notification accesslet options: UNAuthorizationoptions = [.alert,.sound]center.requestAuthorization(options: options) { (granted,error) in   if !granted {      print("Notification access was denIEd")   }}

5秒后,应用程序发出默认声音,但不显示警报内容.我正在尝试前景和后台的应用程序.

解决方法 我有同样的问题.

如果您的内容正文为空(即content.body ==“”),那么即使您拥有标题,也不会收到通知.

因此,解决方案是确保您的内容正文不是空字符串.

总结

以上是内存溢出为你收集整理的ios – 本地通知发出声音但不显示(Swift)全部内容,希望文章能够帮你解决ios – 本地通知发出声音但不显示(Swift)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005622.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存