/**
   * Returns the ApnsService, based on the required profile (production VS sandbox/test). Null is
   * returned if there is no "configuration" for the request stage
   */
  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;
  }
Ejemplo n.º 2
0
  public APNSImpl(String certFileName, String certPassword, boolean sandbox)
      throws FileNotFoundException {
    this.certFileName = certFileName;
    this.certPassword = certPassword;
    this.sandbox = sandbox;

    InputStream certInputStream = new FileInputStream(certFileName);

    ApnsServiceBuilder serviceBuilder =
        com.notnoop.apns.APNS.newService().withCert(certInputStream, certPassword);

    if (sandbox) serviceBuilder = serviceBuilder.withSandboxDestination();

    apns = serviceBuilder.build();
  }