ios - 当用户在“设置”应用中更改推送通知设置时如何获得通知?
问题描述
考虑以下场景:
已安装
应用程序启动
推送通知➝请求
推送通知➝不允许
应用程序关闭或在后台
设置➝用户启用推送通知
如何在不将应用程序移至前台的情况下获得有关此更改的通知,以便即使用户未打开应用程序也可以将设备令牌发送到我们的后端服务器以接收通知?
UNUserNotifications
我知道您可以使用这样的框架检查是否允许通知:
static func checkNotificationStatus() {
UNUserNotificationCenter.current().getNotificationSettings { settings in
switch settings.authorizationStatus {
case .authorized: generatePushToken()
case .provisional: generatePushToken()
case .denied: break
case .notDetermined:
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
checkNotificationStatus()
}
@unknown default: break
}
}
}
但这仅在您的应用程序移至前台或再次启动后才会发生。
如果这些都没有发生怎么办?
解决方案
推荐阅读
- prestashop - 如何在 prestashop 中获取产品的所有类别 ID?(包括子类的子类)
- javascript - 将文件从 s3 下载到本地磁盘
- sql - 返回分组中的计数 0
- r - R - 根据 ID 和日期变量创建新列
- c# - 有条件地添加 IAsyncDisposable?
- android - 通过 startActivityForResult 传递的 Drawable 未打印到 PDF 页面
- flutter - Flutter 嵌套 UI
- python - 用逗号替换空格和新行
- css - 使用媒体查询更改显示属性不起作用
- amazon-web-services - 附加了 ALB 的 EC2 实例在端口 3000 上显示不正常状态