fcm的java实现_支持FCM的Java APNs库

本文探讨了如何使用Java库实现Firebase云消息传递与Apple Push Notification Service (APNs)的集成,以支持跨iOS和Android平台的消息推送。作者分享了一个自定义的FCMSender类示例,用于发送消息到Firebase Cloud Messaging (FCM)端点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

是否有任何支持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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值