PushKit 通知在通话结束后到达

PushKit notification arriving after call has ended

我有一个实现 PushKit 和 CallKit 的应用程序。出现问题的情景如下:

Device A发起呼叫,向Device B发送PushKit通知。 设备 B 没有互联网连接,因此不接听电话。 设备 A 结束通话。 一段时间后,设备 B 连接到互联网。 Device B收到Device A之前发送的PushKit通知,显示CallKit Incoming Call UI.

如您所见,即使在设备 A 结束通话后,设备 B 仍会显示 CallKit 来电 UI。

如何防止设备B接收到来电?

谢谢

您应该通过 PushKit 通知发送结束通话信号,这样,一旦设备 B 重新连接,它就会同时收到开始通话和结束通话通知。

在 iOS13 中,您必须在离开 PushKit 完成处理程序之前报告来电,否则您的应用将被阻止接收进一步的 PushKit 推送。显然,当您遇到呼叫不再存在的情况时,这是一个小问题。

这个场景和其他场景在 Apple Developer Forums thread

中进行了讨论

针对您的情况的具体建议是:

  • While you must report an incoming call immediately, you are still free to decide the call has failed and tell the system later, asynchronously. To do this, call reportCallWithUUID:endedAtDate:reason:. This will tear down the incoming call UI even if the user has not answered the call.
  • If the user is particularly fast at tapping the accept call button, or if the network conditions are poor or there is otherwise a lot of latency, then you should simply wait until the necessary handshakes are complete before calling fulfill on the CXAnswerCallAction. To the user, it simply appears that the call is taking some time to connect, which is a common experience even with standard phone calls.

  • Note that the system takes a few seconds for the incoming call UI to animate in, during which the app has the opportunity to complete this handshake, so this will only have a user-visible impact if it takes a significant time for the handshake to complete.

所以,您需要做的就是报告来电,然后当您确定来电不再有效时(应该不会花很长时间),立即结束通话。