问题描述
自从我安装 iOS 14 以来,我的 iOS 应用出现了问题。(在装有 iOS 13 的设备上使用该应用时没有问题)。问题是在使用我的应用程序几分钟后冻结了一些第三方应用程序(例如 Viber、LinkedIn、Google、Facebook Messenger、Instagram、Slack 等)。只有从设备中删除我的应用程序并重新启动设备后,我才能解决冻结问题。此外,经过大量测试,我们发现如果在我的应用中禁用通知,则不会出现问题。我的应用现在正在使用下一个主要技术: - CoreData + CloudKit 数据镜像(iCloud-CloudKit,后台模式-远程通知功能); - 使用本地计时器; - 调度和处理用户通知。我什至从未意识到某些应用程序会影响另一个应用程序。而且我在研究 StackOverflow、developer.apple.com 论坛等方面找不到任何有用的信息。
一个重要的补充: 当我尝试为 UNNotificationCenter 请求授权时,有时它不会进入闭包(回调)。 调试断点在方法调用行上停止,但在闭包内 - 没有。 也许我对 UNUserNotifications 或远程通知做了一些错误的设置......?
你能帮我解决这个问题吗?这个问题阻止了我的应用程序发布。 这是我用来设置通知的代码:
private func openAppSettings() {
if let url = URL(string: UIApplication.openSettingsURLString) {
DispatchQueue.main.async {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url,options: [:],completionHandler: nil)
}
}
}
}
func checkNotificationsPermissions(completion: @escaping emptyBlock) {
let current = UNUserNotificationCenter.current()
current.getNotificationSettings(completionHandler: { setting in
switch setting.authorizationStatus {
case .authorized:
completion()
case .denied:
self.openAppSettings()
default:
self.setupNotifications(for: UIApplication.shared) {
completion()
}
}
})
}
func setupNotifications(for application: UIApplication,completion: @escaping () -> ()) {
let authOptions: UNAuthorizationOptions = [.alert,.badge,.sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { (success,error) in
DispatchQueue.main.async {
application.registerForRemoteNotifications()
completion()
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)