GCM CCS Receive delivery receipt

狂风中的少年 提交于 2019-12-23 02:26:32

问题


I'm trying to write a 3rd party server .NET application for sending notifications to Android devices using GCM's CCS as outlined here. And I want to use Receive delivery receipts feature.
I created a simple console app using agsXMPP library. My application sends message to GCM with the flag "delivery_receipt_requested": true and receives ACK message from the GCM server, and I see this message is delivered to the target device, but delivery receipt message doesn't come.
Update:
I can receive upstream messages from device. And, finally, I can receive receipts, but it works from time to time. Is it really so unstable feature?
This is my test app:

using System.Threading; using agsXMPP; using agsXMPP.protocol.client;
      class Program
    {
        private static XmppClientConnection xmpp;
        static void Main(string[] args)
        {
            xmpp = new XmppClientConnection
                           {
                               UseSSL = true,
                               UseStartTLS = false,
                               Server = "gcm.googleapis.com",
                               ConnectServer = "gcm.googleapis.com",
                               Port = 5235,
                               Password = "my pwd",
                               Username = "my senderId"
                           };
            xmpp.OnAuthError += OnAuthError;
            xmpp.OnLogin += xmpp_OnLogin;
            xmpp.OnError += OnError;
            xmpp.OnMessage += new MessageHandler(xmpp_OnMessage); //I expected delivery receipt here

            xmpp.Open();

            Console.WriteLine("Press any key to stop ...");
            Console.ReadLine();

        }

        static void xmpp_OnLogin(object sender)
        {
            Console.WriteLine("LoggedOn");

            string msg = string.Format
                ("<message id=\"\">" +
                 "<gcm xmlns=\"google:mobile:data\">" +
                 "{{" +
                 "\"to\":\"{1}\"," +
                 "\"message_id\":\"m-{0}\"" +
                 "\"data\":{{\"somedata\":\"\"}}" +
                 "\"time_to_live\":600," +
                 "\"delay_while_idle\": true," +
                 "\"delivery_receipt_requested\": true}}" +
                 "</gcm>" +
                 "</message>", Guid.NewGuid().ToString(),
                 "device_registartion_id");
            xmpp.Send(msg);          

        }

        static void xmpp_OnMessage(object sender, Message msg)
        {
           //ACK or NACK messages handle here and I expect Delivery receipt here too
           Console.WriteLine("xmpp_OnMessage: " + msg.InnerXml);

       if (msg.InnerXml.Contains("myapp.name")) //delivery receipt or upstream message
       {
           //send an ACK back with message ID
           string msgAck = string.Format
               ("<message id=\"\">" +
                "<gcm xmlns=\"google:mobile:data\">" +
                "{{" +
                "\"to\":\"{1}\"," +
                "\"message_id\":\"{0}\"" +
                "\"message_type\": \"ack\"}}" +
                "</gcm>" +
                "</message>", msg.Id, "device_registartion_id");
           xmpp.Send(msgAck);
       }
           return;
        }


        static void OnAuthError(object sender, agsXMPP.Xml.Dom.Element e)
        {
            Console.WriteLine("OnAuthError: " + e.InnerXml);
        }

        static void OnError(object sender, Exception ex)
        {
            Console.WriteLine("OnError: " + ex.Message); 
        }
    }

来源:https://stackoverflow.com/questions/28146486/gcm-ccs-receive-delivery-receipt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!