[英]iOS and Android Push Notifications from server Java
Server Key = My Firebase Key 服务器密钥=我的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(); } }
Input : Device Token & json body 输入:设备令牌和json正文
in PHP have 在PHP中有
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
Help on this and save my Days , if any changes in rest and can you give sample.. 对此有所帮助,并保存我的Days ,如果休息方面有任何变化,可以举个例子。
I too faced this problem. 我也面临这个问题。
As -AL suggested, I used attribute "notification" in place of "data" and it worked for me. 正如-AL建议的那样,我使用属性“ notification”代替了“ data”,它对我有用。
Sample push message for iOS: "{"notification":{"title":"Title of notification","body":"Your message","attribute3":"vale","attribute4":"vale"....},"to":"Device Token","priority":"high"}" iOS的示例推送消息:“ {” notification“:{” title“:”通知标题“,” body“:”您的消息“,” attribute3“:” vale“,” attribute4“:” vale“ ... 。},“收件人”:“设备令牌”,“优先级”:“高”}“
In the above payload, attribute 3 and 4 are extra attributes that we can add to do perform any action or event like navigating to any particular screen based on the notification. 在上面的有效负载中,属性3和4是我们可以添加以执行任何操作或事件(例如基于通知导航到任何特定屏幕)的额外属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.