公司项目有一套即时的视频语音聊天功能,产品但愿是当App切入后台挂起或者被用户划掉后,收到视频语音推送时,App能够持续震动及响铃(持续震动及响铃),而且用户点击通知时,App启动后就能够及时的进行视频语音通话(用户无等待)。html
苹果推送有三种方案: 1.普通推送 2.静默推送 3.VoIP推送bash
针对三种推送方案的说明,网上有不少很详细的资料,这里就不一一列举。咱们很快的就能够锁定,若是要实现以上需求,VoIP是咱们惟一能够选择的方案。 在Xcode11以前,咱们能够直对接VoIP推送,惟一面临的是苹果的审核。可是前段时间苹果发布了一则通知:微信
Important
On iOS 13.0 and later, if you fail to report a call to CallKit, the system will terminate your app. Repeatedly failing to report calls may cause the system to stop delivering any more VoIP push notifications to your app. If you want to initiate a VoIP call without using CallKit, register for push notifications using the UserNotifications framework instead of PushKit. For more information, see UserNotifications.
复制代码
经过Xcode11咱们收到VoIP推送时,若是咱们没有调用Callkit相关代码,即reportNewIncomingCallWithUUID,咱们会直接收到如下崩溃信息:app
Apps receving VoIP pushes must post an incoming call (via CallKit or IncomingCallNotifications) in the same run loop as pushRegistry:didReceiveIncomingPushWithPayload:forType:[withCompletionHandler:] without delay.
*** Assertion failure in -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes], /BuildRoot/Library/Caches/com.apple.xbs/Sources/PushKit/PushKit-37/PKPushRegistry.m:343
复制代码
显然苹果为了不咱们不正当的使用VoIP推送,进行了强制处理,因此咱们须要对接CallKit咯?若是这样作了,在提交的时候,如下信息可能在等着你:ide
Apple Dear Developer,
The Chinese Ministry of Industry and Information Technology (MIIT) http://www.miit.gov.cn/n1146285/ ... n3057713/index.html requested that CallKit functionality be deactivated in all apps available on the China App Store.
Since your app currently includes CallKit and is available for sale on the China App Store, you will need to submit an update that removes CallKit functionality in China.
VOIP call functionality continues to be allowed but can no longer take advantage of CallKit ’ s intuitive look and feel. CallKit can continue to be used in apps outside of China.
If you have questions or do not believe your app is subject to this update, please contact MIIT.
Best regards,
App Store Review
复制代码
那咱们经过手机号码等条件,进行区域处理。国内使用普通推送,国外经过VoIP来作应该能够经过苹果要求,可是老板不一样意了,咱们面向的是国内用户。仿佛已经撞到南墙了!oop
那让咱们先来对比下几个大厂如何作的。post
BOSS: QQ、微信都实现了,你为何实现不了。。。学习
既然这些App都收到了VoIP推送而且激活了App,同时没有出现CallKit的电话界面,说明经过某些方式是能够实现的。那我就把重点放在了当咱们调用reportNewIncomingCallWithUUID方法的时候,系统作了什么。若是能够找到,那咱们就能够偷偷地作个好心人帮系统作一下。ui
尝试打印当前全部线程内的方法调用,看这个过程当中,是否有一些不同的方法被调用,使人遗憾的是并无找到有用的信息。this
监听全部通知的发送,是否经过一些通知进行了信息传递。这这个过程当中,咱们发现有一个不同的通知出现:PKPushIncomingCallReportedNotification。 而后让咱们试试再也不调用reportNewIncomingCallWithUUID方法,而是发送这个通知呢?结果正是咱们想要的!没有CallKit的通话界面,App有没有异常崩溃通知。
可是偶尔会出现没法再次收到VoIP的push通知。 高重现场景为:收到VoIP推送后长时间不处理,客户端会被异常终止,以后就收不到了。可是收到时客户端激活,就没有问题。
目前工做有其余更紧急的插入进来,暂时没有继续研究了(后面抽时间再看)。这里只是提供了一种解决问题的思路,咱们不能由于认为作不到就不去尝试。
若是有朋友有更好的思路或者存在问题解决方案找到了,能够回复用来帮助更多的人学习。
同时呢,这种方式只是咱们挑战本身的方式,上架App仍是要遵照苹果规范的!