【发布时间】:2017-09-22 14:05:17
【问题描述】:
- 我正在使用 Spring Boot 和 Spring 项目
- 我开发了一个休息电话 &
- FCM_URL = https://fcm.googleapis.com/fcm/send
-
服务器密钥 = 我的 Firebase 密钥
@RequestMapping(value = "/push/notification") public void sendNotification(@RequestParam String Mobiletoken, @org.springframework.web.bind.annotation.RequestBody FcmRequestObject message) throws JsonParseException, JsonMappingException, IOException { OkHttpClient client = new OkHttpClient(); ObjectMapper mapper = new ObjectMapper(); JSONObject obj = new JSONObject(message); System.out.println("Here sending notification request/..."); RequestBody body = new FormBody.Builder().add("to", tokens).add("data", obj.toString()).build(); System.out.println(obj.toString()); Request request = new Request.Builder().url(ApplicationConstants.FCM_URL) .addHeader("Authorization", "key=" + ApplicationConstants.FCM_SERVER_KEY).addHeader("Content-Type", "application/json").post(body) .build(); try { Response response = client.newCall(request).execute(); System.out.println(response.isSuccessful() + " - " + response.code()); } catch (IOException e) { e.printStackTrace(); } } 输入:设备令牌和 json 正文
- 能够获得通知的 Android 设备
- 但是 IOS 设备无法获得通知 [我们已经从带有服务器密钥和设备令牌的 firebase 控制台进行了测试,它只能从他们无法获得的服务器获得]
- 需要对 IOS 的 Rest Call 进行任何更改?
-
在PHP中有
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high'); 帮助解决这个问题并节省我的时间,如果休息有任何变化,您能否提供示例..
- 提前谢谢你..
【问题讨论】:
-
您知道 iOS 和 Android 处理通知的方式不同吗?您以什么方式在您的 iOS 应用程序中接收通知。请添加您的代码。
-
同意@Barns52 Android 和 iOS 处理 FCM 有效负载的方式不同,因此建议为两个平台使用单独的有效负载。您当前正在发送 Android 正确接收的
data消息负载。尝试将带有"priority": "high"的notification消息负载发送到iOS。 -
你可以查看这个答案stackoverflow.com/a/51172021/3073945
标签: ios spring firebase spring-boot firebase-cloud-messaging