package com.insigno.apns;


import javapns.back.PushNotificationManager;
import javapns.back.SSLConnectionHelper;
import javapns.data.Device;
import javapns.data.PayLoad;

public class INAPNSSender {
	
	public static void initializeAPNS(String certificateURL, String secret) throws Exception {
		
		PushNotificationManager.getInstance().initializeConnection("gateway.sandbox.push.apple.com", 2195, certificateURL , secret, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
		
	}
	
	public static void addDevice(String deviceName,String deviceID) throws Exception {
		PushNotificationManager.getInstance().addDevice(deviceName, deviceID);
	}
	
	
	public static void send(String device, String alert, int badge, String sound) throws Exception {
		PayLoad simplePayLoad = new PayLoad();
		simplePayLoad.addAlert(alert);
		simplePayLoad.addBadge(badge);
		simplePayLoad.addSound(sound);

		Device client = PushNotificationManager.getInstance().getDevice(device);
		PushNotificationManager.getInstance().sendNotification(client, simplePayLoad);
	}
	
}
