我第一次使用Firebase推送通知服务,但iOS出现问题。 我用Java编写了后端部分,通知功能适用于android,但不适用于iOS。 这是我的初始化配置
@SneakyThrows
@PostConstruct
public void init() {
FileInputStream serviceAccount =
new FileInputStream("firebaseAccountPrivateKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://databaseNam.firebaseio.com")
.build();
this.firebaseApp = FirebaseApp.initializeApp(options);
}
我通过这种方法发送通知
@SneakyThrows
public void sendNotification(long userId) {
Map<String,String> dataMap = new HashMap<>();
dataMap.put("title","1");
dataMap.put("body","2");
FIREBASE_TOKEN_MAP.get(userId).forEach(token -> {
try {
Message message = Message.builder()
.setToken(token)
.putAllData(dataMap)
.build();
FirebaseMessaging.getInstance(this.firebaseApp).send(message);
}catch (Exception e){
e.printStackTrace();
}
});
}
我检查了IOS令牌没关系 我是通过Firebase控制台发送消息的,问题不是出自令牌 我认为问题出在后端,但我仍然找不到问题所在。 请帮助我