be.mjosoft.ios.apn.example.Example Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of MjoSoft-APNService Show documentation
Show all versions of MjoSoft-APNService Show documentation
Java library for easy integration into the Apple Push Notification Service in a Java application.
The newest version!
package be.mjosoft.ios.apn.example;
import be.mjosoft.ios.apn.APNException;
import be.mjosoft.ios.apn.APNFeedBackService;
import be.mjosoft.ios.apn.APNMessage;
import be.mjosoft.ios.apn.APNService;
import java.text.SimpleDateFormat;
import java.util.List;
/**
* Example class.
* @author mj
*/
public class Example
{
public static void main(String args[]) throws APNException
{
sendNotifications();
checkFeedback();
}
/**
* Check the feedback service.
* @throws APNException
*/
public static void checkFeedback() throws APNException
{
APNFeedBackService service = new APNFeedBackService();
service.initConnexion("", "", "PKCS12");
List devices = service.retreiveObsoleteDevices();
service.endConnection();
for(APNFeedBackService.ObsoleteDevice device : devices){
System.out.println(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(device.getTimestamp().getTime()) + " > " + device.getToken());
}
}
/**
* Sends notifications.
* @throws APNException
*/
public static void sendNotifications() throws APNException
{
// Create the service.
APNService service = new APNService();
service.initConnexion("", "", "PKCS12");
// Create a simple notification.
APNMessage msgA = new APNMessage("Alert message", 1, "default");
System.out.println(msgA);
// Send the notification
service.sendAPN("", msgA);
// Increments the badge value.
msgA.incrementBadge(2);
// Send the notification
service.sendAPN("", msgA);
// Create a complexe notification.
APNMessage msgB = new APNMessage();
APNMessage.CustomAlert customAlert = new APNMessage.CustomAlert();
customAlert.setBody("Another message");
customAlert.setLocalizedActionKey("play");
customAlert.setLocalizedMessageKey("message1.key");
customAlert.setLocalizedMessageArguments("John", "Mary", "1");
msgB.setCustomAlert(customAlert);
System.out.println(msgB);
// Send the notification.
service.sendAPN("", msgB);
service.endConnection();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy