1

ios に通知をプッシュするために javapns を使用し、Android デバイスに通知をプッシュするために android.gcm.server を使用しました。しかし、1 つの通知を多くのデバイスに送信すると、各デバイスに通知の複数のコピーが送信されます。この数は 2 の場合も 3 の場合もあります。何か案は ?

私のコードは以下の通りです

public void pushNotificationsToAndroid(String pushMessage,
            String contentType, String content, String notification_id,
            List<String> devices) {



        try {

            Sender sender = new Sender(
                    properties
                            .getProperty("notification.android.senderIdDemo"));
            com.google.android.gcm.server.Message message = new com.google.android.gcm.server.Message.Builder()
                    .collapseKey("1").timeToLive(3).delayWhileIdle(true)
                    .addData("message", pushMessage)
                    .addData("content_type", contentType)
                    .addData("content", content)
                    .addData("notification_id", notification_id).build();

            MulticastResult result = sender.send(message, devices, 1);

            if (result.getResults() == null) {

                System.out.println(result.getFailure());
                logger.debug("getFailure() of sender.send() method :",
                        result.getFailure());

            }
        } catch (Exception exception) {
            logger.error("erorr push notification ");

        }

        System.out.println("sent not at " + new Date());
        logger.debug(
                "exit pushNotificationsToAndroid() method : current time is ",
                new Date());

    }

    public void pushNotificationsToIOS(String pushMessage, String contentType,
            String content, String notification_id, List<String> devices)
             {


        boolean production = true;
        String password = properties
                .getProperty("notification.ios.password");

        String keyStroke = properties
                .getProperty("notification.ios.certFileName");

        AppleNotificationServer jksServer = null;


        try {

            jksServer = new AppleNotificationServerBasicImpl(keyStroke,
                    password, ConnectionToAppleServer.KEYSTORE_TYPE_JKS,
                    production);

        } catch (KeystoreException keystoreException) {

            logger.error("erorr creating jksServer");

        }

        PushNotificationPayload payload = PushNotificationPayload.complex();

        try {

            payload.addAlert(pushMessage);

        } catch (JSONException e2) {

            logger.error("erorr creating payload alert");

        }

        try {

            payload.addCustomDictionary("content_type", contentType);

        } catch (JSONException e1) {

            logger.error("erorr creating payload content_type");

        }

        try {

            payload.addCustomDictionary("content", content);

        } catch (JSONException e1) {

            logger.error("erorr creating payload content");

        }

        try {

            payload.addCustomDictionary("notification_id", notification_id);

        } catch (JSONException e1) {

            logger.error("erorr creating payload notification_id");

        }

        PushNotificationManager pushManager = new PushNotificationManager();

        try {

            pushManager.initializeConnection(jksServer);

        } catch (CommunicationException | KeystoreException e) {

            logger.error("erorr connecting Server");


        }
        try {

            List<PushedNotification> notifications = pushManager
                    .sendNotifications(payload, Devices.asDevices(devices));


        } catch (CommunicationException | KeystoreException e) {

            logger.error("erorr push notifications");

        }

    }
4

1 に答える 1