是否有任何支持Firebase云消息传递的Java APNs库,我找到了Pushy,但它看起来不支持FCM。
我面临的挑战是能够通过我自己的应用服务器上的Firbase Cloud Messaging发送iOS,Android,Web推送通知,而不是通过Firebase控制台发送。到目前为止,我已经有一些代码,据我所知,它可以用于Android设备的FCM,我已经测试过它,并且可以在我的Android设备上收到通知。 (我也测试了Pushy for iOS,它工作正常,但我需要能够通过https://fcm.googleapis.com/fcm/send将通知发送到我的iOS设备)
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();
}而FCMSender是一个自定义类,它扩展了GCM发件人类,但指向端点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();
}
}我可以在iOS设备的Pushy库中以某种方式执行相同的技巧,以便发送到端点https://fcm.googleapis.com/fcm/send,如果是,那么该怎么办?如果没有,那么是否有一个java APNs库,如开头所述,支持FCM。