我正在使用后台刷新来安排本地通知并更新我的小部件。
问题是没有调用任务注册方法!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.Mahmoud.AdaniLite.AppRefresh", using: nil) { task in
print("Registered")
self.handleAppRefresh(task: task as! BGAppRefreshTask)
}
return true
}
我里面也有一个断点register带有打印语句的方法,但两者都不起作用!
我已经完成了研究,到目前为止我已经尝试了以下方法:
- 我确保 info.plist 中的“允许的后台任务调度程序标识符”填充了正确的任务标识符。我已经三次检查该字符串是否在代码中也正确使用。
- 启用“后台获取”功能。
- 在 info.plist 中,我将“应用程序在后台处理数据”添加到“所需的后台模式”中
- 我正在运行 iOS 15 的真实设备上运行该应用程序
非常感谢任何帮助或指导!
到目前为止您只注册了您的任务处理程序。您还需要安排后台任务。
请参阅本指南了解更多信息:https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app
后台任务何时执行可能有点不可预测,并且可能根本不会按照您期望的时间发生。
这概述了如何调试任务处理程序以确保它们已注册并提交了正确的请求:https://developer.apple.com/documentation/backgroundtasks/starting_and_terminate_tasks_during_development https://developer.apple.com/documentation/backgroundtasks/starting_and_terminating_tasks_during_development
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)