Package com.notnoop.apns

Examples of com.notnoop.apns.ApnsServiceBuilder


    private ApnsService buildApnsService(iOSVariant iOSVariant, final NotificationSenderCallback notificationSenderCallback) {

        // this check should not be needed, but you never know:
        if (iOSVariant.getCertificate() != null && iOSVariant.getPassphrase() != null) {

            final ApnsServiceBuilder builder = APNS.newService().withNoErrorDetection();

            // using the APNS Delegate callback to trigger our own notifications for success/failure status:
            builder.withDelegate(new ApnsDelegateAdapter() {
                @Override
                public void messageSent(ApnsNotification message, boolean resent) {
                    notificationSenderCallback.onSuccess();
                }

                @Override
                public void messageSendFailed(ApnsNotification message, Throwable e) {
                    logger.log(Level.SEVERE, "Error sending payload to APNs server", e);
                    notificationSenderCallback.onError("Error sending payload to APNs server");
                }
            });

            // add the certificate:
            try {
                ByteArrayInputStream stream = new ByteArrayInputStream(iOSVariant.getCertificate());
                builder.withCert(stream, iOSVariant.getPassphrase());

                // release the stream
                stream.close();
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Error reading certificate", e);

                // indicating an incomplete service
                return null;
            }

            // pick the destination:
            if (iOSVariant.isProduction()) {
                builder.withProductionDestination();
            } else {
                builder.withSandboxDestination();
            }

            // create the service
            return builder.build();
        }
        // null if, why ever, there was no cert/passphrase
        return null;
    }
View Full Code Here


  }

  @PostConstruct
  public void start() throws Exception {

    ApnsServiceBuilder builder = APNS.newService();
    InputStream in = _keystoreResource.getInputStream();
    builder.withCert(in, _keystorePassword);

    if (_production)
      builder.withProductionDestination();
    else
      builder.withSandboxDestination();

    _service = builder.build();
    _service.start();

    loadInactiveDevices();

    _executor = Executors.newSingleThreadScheduledExecutor();
View Full Code Here

    private ApnsService buildApnsService(iOSVariant iOSVariant, final NotificationSenderCallback notificationSenderCallback) {

        // this check should not be needed, but you never know:
        if (iOSVariant.getCertificate() != null && iOSVariant.getPassphrase() != null) {

            final ApnsServiceBuilder builder = APNS.newService().withNoErrorDetection();

            // using the APNS Delegate callback to trigger our own notifications for success/failure status:
            builder.withDelegate(new ApnsDelegateAdapter() {
                @Override
                public void messageSent(ApnsNotification message, boolean resent) {
                    notificationSenderCallback.onSuccess();
                }

                @Override
                public void messageSendFailed(ApnsNotification message, Throwable e) {
                    logger.log(Level.SEVERE, "Error sending payload to APNs server", e);
                    notificationSenderCallback.onError("Error sending payload to APNs server: " + e.getMessage());
                }
            });

            // add the certificate:
            try {
                ByteArrayInputStream stream = new ByteArrayInputStream(iOSVariant.getCertificate());
                builder.withCert(stream, iOSVariant.getPassphrase());

                // release the stream
                stream.close();
            } catch (Exception e) {
                logger.log(Level.SEVERE, "Error reading certificate", e);

                // indicating an incomplete service
                return null;
            }

            // pick the destination:
            if (iOSVariant.isProduction()) {
                builder.withProductionDestination();
            } else {
                builder.withSandboxDestination();
            }

            // create the service
            return builder.build();
        }
        // null if, why ever, there was no cert/passphrase
        return null;
    }
View Full Code Here

    private ApnsService buildApnsService(iOSVariant iOSVariant) {

        // this check should not be needed, but you never know:
        if (iOSVariant.getCertificate() != null && iOSVariant.getPassphrase() != null) {

            final ApnsServiceBuilder builder = APNS.newService();

            // add the certificate:
            ByteArrayInputStream stream = new ByteArrayInputStream(iOSVariant.getCertificate());
            builder.withCert(stream, iOSVariant.getPassphrase());

            try {
                // release the stream
                stream.close();
            } catch (IOException e) {
                logger.log(Level.SEVERE, "Error reading certificate", e);
            }

            // pick the destination:
            if (iOSVariant.isProduction()) {
                builder.withProductionDestination();
            } else {
                builder.withSandboxDestination();
            }

            // create the service
            return builder.build();
        }
        // null if, why ever, there was no cert/passphrase
        return null;
    }
View Full Code Here

TOP

Related Classes of com.notnoop.apns.ApnsServiceBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.