【问题标题】:NotificationCenter requestAuthorization alert failing to display when returning from the background从后台返回时,NotificationCenter requestAuthorization 警报无法显示
【发布时间】:2021-03-10 16:13:02
【问题描述】:

我正在请求用户授权以发送通知,这样做时会弹出警报并显示默认通知消息和Don't allow / Allow 按钮,正如预期的那样。

但是,如果我没有选择应用程序背景,然后再次重新打开应用程序,我无法让警报再次显示。

我可以再次强制调用 requestAuthorization,并且我在完成块中正确地看到授权请求是错误的(因为之前没有做出选择)。

let options: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in
     // granted = false
}

但是为什么提示不再显示呢?

如有任何澄清,我们将不胜感激。

作为旁注,我注意到在请求用户位置时,在做出选择之前,我什至无法最小化应用程序!

【问题讨论】:

    标签: swift push-notification nsnotificationcenter


    【解决方案1】:

    显然是这样设计的。

    将应用发送到后台时自动设置为false。

    当您的应用第一次发出此授权请求时,系统 提示用户批准或拒绝请求并记录用户的 回复。后续授权请求不会提示用户。

    来源:https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications

    【讨论】:

      猜你喜欢
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 2021-10-12
      • 1970-01-01
      • 2011-10-22
      • 2016-08-08
      • 2017-12-13
      相关资源
      最近更新 更多