Is there a way to discard a VoIP push notification call request?

拥有回忆 提交于 2020-12-15 03:50:16

问题


I'm implementing an intercom feature, which by specs should report and allow one call only, ignoring any call request if there's one already reported or answered (in progress).

The simplest thing to do is to ignore the VoIP push notification message of subsequent calls, but that is disallowed by Apple, because if a notification is not followed by a call to CXProvider's reportIncomingCall(with:update:completion), the app is terminated (I guess this is to prevent using these notifications for other purposes, questionable choice...).

So, even if a call must be discarded, the push notification handler must still call that method. I tried calling reportIncomingCall(), followed up by an end of call request, using either:

self.provider.reportNewIncomingCall(with: uuid, update: update) { error in
  self.provider.reportCall(with: uuid, endedAt: Date(), reason: .answeredElsewhere)
}

and

self.provider.reportNewIncomingCall(with: uuid, update: update) { error in
  let endCallAction = CXEndCallAction(call: uuid)
  let transaction = CXTransaction(action: endCallAction)
  self.controller.request(transaction) { error in
  }  
}

(note that this is not the actual code I'm using, as the architecture is a bit more elaborated in the project)

where controller is an instance of CXCallController. I also tried with a combination of both, but the 2nd call is still reported and I have to manually end it.

Is there a "legal" way to discard a VoIP call request? I haven't found anything in the documentation, just the rule that each VoIP push notification must be followed by a call to reportIncomingCall().


回答1:


I know that the documentation says that each VoIP push notification must report a new incoming call. But, as far as I can tell, as long as you already have an active call you're free to receive any VoIP push without having to report another new incoming call.

I don't know if it's just the documentation that is imprecise or if Apple plans to remove also this possibility in the future, but the fact is that it is working. I have an app published in the App Store that works without any problem and I just do what you'd like to do: ignore any additional VoIP push if a call is already in progress.

The thing is: it's clear the reason why Apple forces us to report a new incoming call upon receiving a VoIP push, isn't it? But, as long as a call is in progress, your app is active and running, right? Why should they limit the use of VoIP pushes also in this situation? Anything you can do with a VoIP push, you can do it also without a VoIP push as long as the app is running.




回答2:


It turns out I made a mistake in my code - I was passing the wrong identifier to reportCall(with:endedAt:reason:), so it was not ending the call that was just reported. So this code works fine:

self.provider.reportNewIncomingCall(with: uuid, update: update) { error in
  self.provider.reportCall(with: uuid, endedAt: Date(), reason: .answeredElsewhere)
}

It makes Apple happy :-)., and no UI about that canceled call is shown to the user.

Be sure to also read @Marco's answer. That would definitely be a good way to decline calls (by just ignoring the notification), but since it's not explicitly mentioned in the documentation, I don't want to find out in the future that Apple has changed the way it works.



来源:https://stackoverflow.com/questions/62299132/is-there-a-way-to-discard-a-voip-push-notification-call-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!