简体   繁体   English

Firebase响应 - 空值响应

[英]Firebase response - null values response

I am using firebase notifications in my android app and spring backend. 我在我的Android应用程序和spring后端使用firebase通知。

Everything was working fine, but maybe something gone wrong after I release my android version to google play store for testing. 一切都运行正常,但在我将我的Android版本发布到谷歌游戏商店进行测试后,可能会出现问题。 Now I have this response: 现在我有这个回应:

FirebaseResponse{multicast_id=0, success=null, failure=null, canonical_ids=null, results=null}

The notifications are sent and everything works fine, but why I am getting a null values in my Spring backend? 通知发送,一切正常,但为什么我在我的Spring后端获得空值?

My backend java spring code: 我的后端java spring代码:

 @RequestMapping(value = "/send", method = RequestMethod.GET, 
   produces = "application/json")
   public ResponseEntity<String> send() {


    JSONObject body = new JSONObject();
    try {

        body.put("to", "/topics/photos");
        body.put("priority", "high");


        JSONObject notification = new JSONObject();
        notification.put("body", "body string here");
        notification.put("title", "title string here");


        JSONObject data = new JSONObject();
        data.put("lat", "value1");
        data.put("lng", "value2");

        body.put("notification", notification);

        body.put("data", data);

    } catch (JSONException e) {
        e.printStackTrace();
    }

    HttpEntity<String> request = new HttpEntity<>(body.toString());

    CompletableFuture<FirebaseResponse> pushNotification = androidPushNotificationsService.send(request);
    CompletableFuture.allOf(pushNotification).join();

    try {
        FirebaseResponse firebaseResponse = pushNotification.get();
        if (firebaseResponse.getSuccess() == 1) {
            log.info("push notification sent ok!");
        } else {
            log.error("error sending push notifications: " + firebaseResponse.toString());
        }
        return new ResponseEntity<>(firebaseResponse.toString(), HttpStatus.OK);

    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return new ResponseEntity<>("the push notification cannot be send.", HttpStatus.BAD_REQUEST);
}

I get nullpointer here, which is null success: 我在这里得到nullpointer,这是成功的:

firebaseResponse.getSuccess()

What is the cause? 原因是什么? I have topic "photos" defined in my project firebase console. 我在项目firebase控制台中定义了主题“照片”。 What can be the issue, beside everything was working good till today? 可能是什么问题,除了一切都很好,直到今天? Really strange for me. 对我来说真的很奇怪。

Maybe you have more then one deployment environment set and when you launched the application in play store you changed to production and in firebase you only added the data in development. 也许您有多个部署环境集,当您在Play商店中启动应用程序时,您已更改为生产,而在firebase中,您只在开发中添加了数据。 This once was a problem for me, I only set the data in dev and when I released one version to the client, the app was without any data (Staging was empty). 这曾经是我的问题,我只在dev中设置数据,当我向客户端发布一个版本时,应用程序没有任何数据(Staging为空)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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