【问题标题】:iOS and Android Push Notifications from server Java来自服务器 Java 的 iOS 和 Android 推送通知
【发布时间】: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


【解决方案1】:

我也遇到过这个问题。

正如 -AL 建议的那样,我使用属性“通知”代替“数据”,它对我有用。

iOS 推送消息示例: "{"notification":{"title":"通知标题","body":"你的消息","attribute3":"vale","attribute4":"vale"....},"to" :"设备令牌","优先级":"high"}"

在上面的负载中,属性 3 和 4 是额外的属性,我们可以添加它们来执行任何操作或事件,例如根据通知导航到任何特定屏幕。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-26
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-18
    • 1970-01-01
    相关资源
    最近更新 更多