应用程序被杀死时未收到 IOS 13 VOIP 推送通知

Posted

技术标签:

【中文标题】应用程序被杀死时未收到 IOS 13 VOIP 推送通知【英文标题】:IOS 13 VOIP Push Notifications not received when app is KILLED 【发布时间】:2020-09-19 17:58:04 【问题描述】:

我们有一个 Cordova 应用程序,它使用 WebRTC 进行视频聊天。 我们正在使用这个插件来实现 VOIP 推送通知 https://github.com/mattkhaw/cordova-plugin-callkit. 除此之外,我们还使用 AWS SNS 为我们处理 VOIP 推送。 流程是如何工作的?

ios Device Calee (User A)
1. When device opens the app, it registers on Apple servers and 
receives a VOIP Device Token
2. We call Amazon SNS to save the token and get the endpointARN for that token
3. We save the token in the database along with the user ID and endpointARN 
from AWS

Caller Side (User B)
1. User B wants to call User A
2. User B clicks the call button
3. A request it send to the server, which checks if a token exists for User A 
in the database.
4. If it exists, we call AWS SNS endpointARN so it will 
send a VOIP push to User A

当应用程序打开或应用程序处于后台时,所有这些都可以正常工作。 当应用程序被终止(终止)时会出现问题。 当应用程序被终止时,应用程序崩溃,这是我们收到的关于 https://gist.github.com/AleksandarTokarev/74068feadd728a4bd1c672a024482af4 的日志。 我对日志细节做了一些研究,似乎原因写在https://developer.apple.com/forums/thread/124517。

The exception code "0xbaadca11" indicates that your app was killled for failing to report a CallKit 
call in response to a PushKit notificaiton.  That should have been clear in the crash log,
but this particular requirement is implemented through multiple code paths and it looks like this 
one isn't as clear as the others.  For more details on the new requirement, take a look at:
https://developer.apple.com/videos/play/wwdc2019/707/

知道为什么会这样吗?该插件在应用程序运行或后台运行时正常工作。 我正在使用以下负载调用 AWS SNS

let voip_protocol_value = `"aps" :  "alert": "New Incoming Call" ,
 "data" :  "Caller":  "Username" : "$caller", "ConnectionId": "$Random.id()"`
                let payload = 
                payload[`APNS_VOIP`] = voip_protocol_value
                let params = 
                    'Message': JSON.stringify(payload),
                    'MessageAttributes': 
                        'AWS.SNS.MOBILE.APNS.PRIORITY': 
                            'DataType': 'String',
                            'StringValue': '10'
                        ,
                        'AWS.SNS.MOBILE.APNS.PUSH_TYPE': 
                            'DataType': 'String',
                            'StringValue': 'voip'
                        ,
                    ,
                    'MessageStructure': 'json',
                    'TargetArn': user.endpointArn
                

【问题讨论】:

【参考方案1】:

我设法通过以下方式修改插件来解决此问题:https://github.com/luisbouca/cordova-plugin-callkit/compare/master...AleksandarTokarev:master.

app被KILLED(TERMINATED)的时候好像没有调用init()函数,所以我的一个朋友帮我做了小重构,把init()函数代码放到了插件初始化中。

这意味着 Pushkit 没有被初始化(因为它在 init() 方法中)。

init() 方法仍然存在,但在 javascript 中初始化时会调用它。

这可能与我们的 Meteor Cordova 应用程序以及应用程序本身的初始化方式有关。

现在一切正常。

【讨论】:

以上是关于应用程序被杀死时未收到 IOS 13 VOIP 推送通知的主要内容,如果未能解决你的问题,请参考以下文章

iOS在一分钟内杀死CallKit VoIP应用程序在后台工作

react native - 应用程序被杀死/未启动时未收到通知

iOS 13 在后台没有收到 VoIP 推送通知

iOS App处于后台/被杀死的状态仍可进行语言播报的实现 (适配iOS12.1 ,iOS15的本地通知功能)

iOS App处于后台/被杀死的状态仍可进行语言播报的实现 (适配iOS12.1 ,iOS15的本地通知功能)

应用程序在android中终止时未收到通知