简体   繁体   English

来自服务器Java的iOS和Android推送通知

[英]iOS and Android Push Notifications from server Java

  • am using spring boot & spring project 我正在使用Spring Boot和Spring项目
  • i have developed one rest call & 我已经打了一个电话
  • FCM_URL = https://fcm.googleapis.com/fcm/send FCM_URL = https://fcm.googleapis.com/fcm/send
  • 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正文

  • Android Devices able to get Notifications Android设备能够获取通知
  • But IOS Devices not able to get notifications [we have tested from firebase console with server key & device token its working, only from server they not able to get] 但是IOS设备无法获取通知[我们已经从Firebase控制台进行了测试,其中服务器密钥和设备令牌可以正常工作,仅从服务器无法获得通知]
  • need to any changes in Rest Call for IOS? 是否需要对Rest Call for IOS进行任何更改?
  • 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 ,如果休息方面有任何变化,可以举个例子。

  • thank you in advance.. 先感谢您..

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM