无法从UNNotificationServiceExtension内部安排任务-错误:BGTaskSchedulerErrorDomain错误1 [英] Unable to schedule a task from within a UNNotificationServiceExtension - Error: BGTaskSchedulerErrorDomain error 1

查看:73
本文介绍了无法从UNNotificationServiceExtension内部安排任务-错误:BGTaskSchedulerErrorDomain错误1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如标题所示,我目前无法从UNNotificationServiceExtension内安排任务.我想在调用以下函数并因此收到推送的情况下安排任务:

func didReceive(_ request:UNNotificationRequest,withContentHandler contentHandler:@escaping(UNNotificationContent)-> Void)

目前,我一接到电话:

尝试BGTaskScheduler.shared.submit(request)

输入catch子句并返回以下错误:'操作无法完成.(BGTaskSchedulerErrorDomain错误1.)'

推送消息通过以下URL与Firebase云消息发送在一起,并且在我的应用中完美接收: https://fcm.googleapis.com/v1/ {项目路径}.我从POSTMAN中调用此网址.我还指定了访问令牌和json正文.

推送消息中的apns标头设置为"apns-push-type":"background".有效负载.aps具有以下值:"apns-priority":"5","content-available":1,"mutable-content":1.我确认这一切都可以正常进行.

奇怪的是,我确实从真正的应用程序中获取了后台任务来工作,因此没有从UNNotificationServiceExtension内部触发它.我试图检查代码是否真正起作用.

我已经完成了研究,到目前为止,我已经尝试了以下方法:
1..我确保在info.plist中的允许的后台任务计划程序标识符"中填充了正确的任务标识符.我已经三重检查了该字符串是否也正确地在代码中使用.
2.在应用程序中启用了以下功能:后台提取",远程通知",后台处理".
3..在info.plist中,支持以下UIBackgroundMode:音频",获取",处理",远程通知"和语音".这些相同的UIBackgroundModes也在UNNotificationServiceExtension info.plist中输入(我只是为了确定这一点).
4..我确保任务已在'didFinishLaunchingWithOptions'中的AppDelegate中注册.
5..每次实际触发任务时,我都会调用"expirationHandler"和"setTaskCompleted"

任何帮助或指导均深表感谢!
在此先感谢;-)

解决方案

似乎无法在模拟器上安排后台任务,使用模拟器时出现与您相同的错误.在真实设备上运行时,一切都很好.希望对您有帮助.



As the title states, i am currently unable to schedule a task from within a UNNotificationServiceExtension. I would like to schedule the task when the following function is called and thus a push is received:

func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)

Currently as soon as i call:

try BGTaskScheduler.shared.submit(request)

The catch clause is entered and the following error is returned: 'The operation couldn’t be completed. (BGTaskSchedulerErrorDomain error 1.)'

The push messages are send with Firebase cloud messaging via the following url and are received perfectly in my app: https://fcm.googleapis.com/v1/{path to project}. I call this url from within POSTMAN. I also specify the access token and the json body.

The apns header in the push message is set to "apns-push-type": "background". And the payload.aps has the following values: "apns-priority": "5","content-available": 1, "mutable-content": 1. I think this all works correctly, as i verified this.

The strange thing is that i did get the background task to work from just within the actual app, so without firing it from within the UNNotificationServiceExtension. I tried this to check if the code actually works at all.

I have done my research and so far i have tried the following already:
1. I made sure 'Permitted background task scheduler identifiers' in the info.plist is filled with the correct task identifier. I have triple checked that this string gets used correctly in the code as well.
2. Enabled the following capabilities in the app: 'Background fetch', 'Remote notifications', 'Background processing'.
3. In the info.plist the following UIBackgroundModes are supported: 'audio', 'fetch', 'processing', 'remote-notification' and 'voip'. These same UIBackgroundModes are entered in the UNNotificationServiceExtension info.plist as well (i did that just to be sure).
4. I made sure the task gets registered in the AppDelegate in 'didFinishLaunchingWithOptions'
5. I call the 'expirationHandler' and the 'setTaskCompleted' every time the task is actually fired

Any help or guidance is deeply appreciated!
Thanks in advance ;-)

解决方案

It seems that background tasks can not be scheduled on a simulator, I got the same error as you when using the simulator. When running on a real device everything is fine. Hope this could help you.

这篇关于无法从UNNotificationServiceExtension内部安排任务-错误:BGTaskSchedulerErrorDomain错误1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆