From 9edb2caf9396a1b997036d610cd0ec7fb4dd55bb Mon Sep 17 00:00:00 2001 From: imhao183 Date: Mon, 29 Mar 2021 09:56:06 +0800 Subject: [PATCH] =?UTF-8?q?voip=E6=8E=A8=E9=80=81=E5=BD=93=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E4=BD=BF=E7=94=A8pushkit=E6=97=B6=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8background=E6=8E=A8=E9=80=81=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/apns.properties | 5 ++++- .../java/cn/wildfirechat/push/ios/ApnsServer.java | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/config/apns.properties b/config/apns.properties index 85346f9..19299dc 100644 --- a/config/apns.properties +++ b/config/apns.properties @@ -6,4 +6,7 @@ apns.voip_cer_pwd=123456 apns.alert=default apns.voip_alert=ring.caf -apns.voip_feature=true +# 苹果要求使用voip推送必须使用callkit,不然会停掉voip推送。由于大陆政策,callkit被禁止,所以在大陆无法使用voip推送。 +# 苹果政策参考 https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry?language=objc +# 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. +apns.voip_feature=false diff --git a/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java b/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java index c22a6e8..c6d60d5 100644 --- a/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java +++ b/src/main/java/cn/wildfirechat/push/ios/ApnsServer.java @@ -197,7 +197,6 @@ public class ApnsServer { payloadBuilder.setBadgeNumber(badge); payloadBuilder.setSound(sound); - final String payload = payloadBuilder.buildWithDefaultMaximumLength(); final String token; if (service == productVoipSvc || service == developVoipSvc) { token = pushMessage.voipDeviceToken; @@ -213,14 +212,20 @@ public class ApnsServer { if (!mConfig.voipFeature || pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_NORMAL || StringUtils.isEmpty(pushMessage.getVoipDeviceToken())) { if(pushMessage.pushMessageType == PushMessageType.PUSH_MESSAGE_TYPE_NORMAL || StringUtils.isEmpty(pushMessage.getVoipDeviceToken())) { c.add(Calendar.MINUTE, 10); //普通推送 + String payload = payloadBuilder.buildWithDefaultMaximumLength(); pushNotification = new SimpleApnsPushNotification(token, pushMessage.packageName, payload, c.getTime(), DeliveryPriority.CONSERVE_POWER, PushType.ALERT); } else { c.add(Calendar.MINUTE, 1); //voip通知,使用普通推送 - pushNotification = new SimpleApnsPushNotification(token, pushMessage.packageName, payload, c.getTime(), DeliveryPriority.IMMEDIATE, PushType.ALERT); + payloadBuilder.setContentAvailable(true); + payloadBuilder.addCustomProperty("voip", true); + payloadBuilder.addCustomProperty("voip_type", pushMessage.pushMessageType); + payloadBuilder.addCustomProperty("voip_data", pushMessage.pushData); + String payload = payloadBuilder.buildWithDefaultMaximumLength(); + pushNotification = new SimpleApnsPushNotification(token, pushMessage.packageName, payload, c.getTime(), DeliveryPriority.IMMEDIATE, PushType.BACKGROUND); } - } else { c.add(Calendar.MINUTE, 1); + String payload = payloadBuilder.buildWithDefaultMaximumLength(); pushNotification = new SimpleApnsPushNotification(token, pushMessage.packageName + ".voip", payload, c.getTime(), DeliveryPriority.IMMEDIATE, PushType.VOIP); }