Java APNs library with FCM support

1.2k Views Asked by At

Is there any java APNs library out there that has Firebase Cloud Messaging support, I have found Pushy but it looks like it does not support FCM.

I am challenged with being able to send iOS, Android, Web push notifications through Firbase Cloud Messaging from my own app server, and not from the Firebase Console. So far I have some code that as far as I can tell works with FCM for Android devices, I have tested it and I can receive notifications on my Android devices. (I have also tested Pushy for iOS and it works fine, but I need to be able to send the notification to my iOS devices through https://fcm.googleapis.com/fcm/send)

try{
        Sender sender = new FCMSender(serverKey);
        Notification notification = new Notification.Builder("").title("New Message").body("").build();
        Message message = new Message.Builder().notification(notification).addData("data", "Hello World!").build();
        Result result = sender.send(message, "deviceToken", 1);
        System.out.println("Result: " + result.toString());
    } catch(Exception e){
        e.printStackTrace();
    }

and FCMSender is a custom class that extends GCM Sender class but points to the endpoint https://fcm.googleapis.com/fcm/send

public class FCMSender extends Sender {
public FCMSender(String key){
    super(key);
}

@Override
protected HttpURLConnection getConnection(String url) throws IOException{
    String fcmUrl = "https://fcm.googleapis.com/fcm/send";
    return (HttpURLConnection) new URL(fcmUrl).openConnection();
}
}

Can I do the same trick somehow in the Pushy library for iOS devices to send to the endpoint https://fcm.googleapis.com/fcm/send if yes then how? And if not, is there a java APNs library, as mentioned in the beginning, that supports FCM.

0

There are 0 best solutions below