NotificationCenter requestAuthorization alert 后台返回时显示失败

NotificationCenter requestAuthorization alert failing to display when returning from the background

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

但是,如果我在没有进行选择的情况下让应用程序后台运行,然后再次重新打开应用程序,我将无法再次显示警报。

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

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

但为什么警报不再显示?

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

附带说明一下,我注意到在请求用户位置时,我什至无法最小化应用程序,直到做出选择!

显然是这样设计的。

发送app到后台时granted自动设置为false

The first time your app makes this authorization request, the system prompts the user to grant or deny the request and records the user’s response. Subsequent authorization requests don’t prompt the user.

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