I am using notnoop library for sending APNS push. My server is build on java and hosted on tomcat/apache webserver (One static IP). I have 2 iphone application which is on app store. Both having there app id and certificates. When I try to send push from our server, it is sending push only to that App which certificate initialise first time. Suppose I have 2 application, AppA and AppB, they have 2 different app id, AppIDA and AppIDB and they have there own certificates (.p12) CertiA and CertiB. After I restarted our tomcat server and if one push initiated let say AppA, it will deliver to device successfully. If the another push initiated for another App AppB, it will not deliver to device. I cant understand why this happen. Both certificate I tested individually and both are working fine. Below is java code.
This code creates new instance every time for each App AppA and AppB.
import com.notnoop.apns.APNS;
import com.notnoop.apns.ApnsService;
import com.notnoop.apns.ApnsServiceBuilder;
//This is the class to send the PUSH
public class APNSConnectionImpl extends MessagingConnection {
//APNS Builder, using notnoop library
ApnsServiceBuilder apnsServiceBuilder = null;
//APNS Service, using notnoop library
ApnsService apnsService = null;
// This function is use to send PUSH
// Parameters:
// deviceAndPaylodiOS : List of Devices and Payload
// appRegistrationKey : Name of the certificate, It could be AppA Certificate or //AppB Certificate. The certificate comes at runtime and both certificates copy and //past in a specific folder lat say /var/apncertificate/AppACertificate.p.12 and /var/apncertificate/AppBCertificate.p.12
@Async
@Override
public HashMap<String, String> sendMessagePool(Map<String, String> deviceAndPaylodiOS, String appRegistrationKey)
throws ApplicationException {
initializeApnsServices(appRegistrationKey);
if (deviceAndPaylodiOS == null || deviceAndPaylodiOS.isEmpty()) {
return null;
}
// Sending Push to all devices,
deviceAndPaylodiOS.forEach((key, value)->{
apnsService.push(key, value);
});
if (apnsService != null) {
apnsService.stop();
apnsService = null;
apnsServiceBuilder = null;
}
return null;
}
private void initializeApnsServices(String appRegistrationKey) throws ApplicationException{
if (apnsServiceBuilder != null) {
apnsServiceBuilder = null;
}
apnsServiceBuilder = APNS.newService();
try {
String certPath = "/var/apnscertificates/"+ appRegistrationKey;
apnsServiceBuilder.withCert(certPath,Constants.APNS_PASS_CERTIFICATE).withProductionDestination();
} catch (Exception e) {
e.printStackTrace();
throw new QuinchyApplicationException("APNS certificate problem");
}
if (apnsService != null) {
apnsService.stop();
apnsService = null;
}
apnsService = apnsServiceBuilder.build();
}
}