无法向 iOs 台设备发送通知

Failed to send notifications to iOs devices

我正在实施来自 .jar 的通知, work perfectly, but lately the notifications in 中的通知给我一个 错误,如下所示:

Delivery error: javapns.notification.exceptions.PayloadMaxSizeExceededException:
Total payload size exceeds allowed limit (payload is 259 bytes, limit is 256)

我使用的代码如下:

    //El metodo de multithread payload hace return unicamente cuando todos los hilos han finalizado de poner las notificaciones.
    //Como no queremos esperar a que termine ponemos el codigo en un hilo separado para que pueda continuar y no se quede colgado el WS.            
    Thread thread = new Thread(){
        public void run(){              
            try {           
                final List<String> idsDispositivos = new ArrayList<String>();                   

                final String keystore = XmlUtils.dirCertIOS + XmlUtils.nomCertificado;
                final String password = XmlUtils.password;
                final boolean production = XmlUtils.production;

                //Obtenemos los ids de los dispositivos
                for(DispositivoDto r : dispositivos)
                     idsDispositivos.add(r.getIdDispositivo());                  

                // Creamos el payload con los campos que necesitemos       
                PushNotificationPayload payload = PushNotificationPayload.complex();    

                /* Customize the payload */ 
                payload.addAlert(textoES);   
                payload.setContentAvailable(true);

                payload.addCustomDictionary("es", textoES);
                payload.addCustomDictionary("en", textoCA);
                payload.addCustomDictionary("ca", textoEN);
                payload.addCustomDictionary("tiponotificacion", tipoNotificacion);  

                List<PushedNotification> notifications = new ArrayList<PushedNotification>();

                if(idsDispositivos.size()<= 200){
                    /* Push your custom payload */    
                    notifications = Push.payload(payload, keystore, password, production, idsDispositivos);

                // Si hay mas de 200 dispositivos creamos diferentes hilos utilizando el multithread payload
                } else {
                    // Decidimos cuantos hilos vamos a crear y usar
                    int threads = 30;

                    if(dispositivos.size() > 200) {
                        threads = (int) Math.ceil(dispositivos.size()/200);
                    }else{
                        threads = 1;
                    }

                    // empezamos los hilos, esperamos a que terminen, y se coge la lista de notificaciones
                    notifications = Push.payload(payload, keystore, password, production, threads, idsDispositivos);
                }

                //Gestion de los resultados del envio de notificaciones 
                int dispEliminados = 0;
                int dispNotificados = 0;

                for (PushedNotification notification : notifications) {
                    if (notification.isSuccessful()) {
                        dispNotificados ++;
                        // Apple accepta la notificacion y debe enviarla
                    } else {
                        String invalidToken = notification.getDevice().getToken();

                        //obtenemos el indice del dispositivo en la lista de dispositivos
                        int index = idsDispositivos.indexOf(invalidToken);

                        //obtenemos la informacion del dispositivo a borrar
                        Integer usuario = dispositivos.get(index).getUsuario();
                        String idHardware = dispositivos.get(index).getIdHardwareDis();

                        //quitamos el dispositivo de nuestra BD
                        aBD.unregisterDispositivo(usuario, invalidToken,idHardware);
                        dispEliminados ++;                          

                        //Encontramos mas informacion sobre el problema ocurrido
    //                  Exception theProblem = notification.getException();
    //                  theProblem.printStackTrace();

                        //If the problem was an error-response packet returned by Apple, get it
                        ResponsePacket theErrorResponse = notification.getResponse();

                        if (theErrorResponse != null){
                            logNot.info("IOS: " +theErrorResponse.getMessage());
                        }
                    }
                }
            } catch (CommunicationException e) {
                logNot.error("IOS: Error en envio notificaciones - CommunicationException: ",e);
            } catch (KeystoreException e) {
                logNot.error("IOS: Error en envio notificaciones - KeystoreException: ",e);
            } catch (JSONException e) {
                logNot.error("IOS: Error en envio notificaciones - JSONException: ",e);
            } catch (Exception e) {
                logNot.error("IOS: Error en envio notificaciones",e);
            }
        }
    };

    thread.start();

有什么想法吗?

我猜您使用的是已弃用的 Javapns 实现,它使用旧的 APNS 负载大小限制。随着您的有效载荷越来越大,您开始面临这个问题。我想你可以尝试一个 javapns 更新的实现,比如 this.

我设法消除了错误:

Delivery error: javapns.notification.exceptions.PayloadMaxSizeExceededException:
Total payload size exceeds allowed limit (payload is 259 bytes, limit is 256)

为此,我必须修改以下行:

PushNotificationPayload payload = PushNotificationPayload.complex(); 

其他人:

PushNotificationPayload payload = PushNotificationBigPayload.complex();