GCM在Android上正常运行,但无法在iOS上运行

时间:2015-07-14 13:38:30

标签: android ios google-cloud-messaging

我已经成功地为Android实现了GCM,但是当我尝试将其实现到我的iOS版本时,我将无法获得推送消息。

我在iOS版本上获得了gcm令牌,并且可以发送消息(我使用Postman)。 我得到了一个成功的响应和一个唯一的消息ID,但没有收到推送。几天来我一直在努力。

我尝试创建一个新的GCm项目,并且还运行iOS的GCM示例,但没有任何作用。

我在iOS和Android上使用的帐号与apiKey相同。

邮递员代码:

{
          "collapse_key": "score_update",
          "time_to_live": 108,
          "delay_while_idle": true,
          "data": {
            "score": "4x8",
            "time": "15:16.2342"
          },
          "registration_ids":["My Token"],
}

我错过了什么?

2 个答案:

答案 0 :(得分:6)

我遇到了同样的问题,并且使用content_available和priority选项修复了这个问题,如下面的文档所示:

您应发送“content_available”:true “priority”:“high”,

https://developers.google.com/cloud-messaging/http-server-ref

enter image description here

示例JSON请求:

class MyClass {
    void myMethod() {
        System.out.println("Testing");
    }
}

public class MainClass {
    public static void main(String[] args) {
        foo();
    }
    void foo() {
        MyClass a = new MyClass();
        a.myMethod();
    }
}

答案 1 :(得分:3)

难以置信,不得不用“通知”更改“数据”。 iOS的有效负载有点不同。更多信息可以在here

找到