dongqiancui9194
dongqiancui9194
2015-08-30 22:23

上游消息 - iOS GCM

  • php
  • ios

I'm trying to implement Google Messaging in my app and server using Xamarin API. The downstream messages (server to app) is working great, but i can't get the upstream working.

At server side i'm using PHP with XMPP library (JAXL), with that i can auth at GCM server and send messages to devices. I've registered to receive messages with this code:

$XMPPClient->add_cb("on__message", function($stanza){ 

        echo "new message";
        $data = json_decode(html_entity_decode($stanza->childrens[0] -> text), true);
        $messageType = $data['message_type'];
        $messageId = $data['message_id']; //message id which was sent by us
        $gcmKey = $data['from']; //gcm key;
        ...
        });

At client, i'm using the GCM api call SendMessage:

    public class SendClass : ReceiverDelegate
{
    public void SendMessage(string Message)
    {
        InstanceId.SharedInstance.Start(Google.InstanceID.Config.DefaultConfig);

        Service.SharedInstance.SendMessage(new NSDictionary("key", "value"), @"SenderID@gcm.googleapis.com", "Message");
    }

    public override void DidSendDataMessage(string messageID)
    {
        base.DidSendDataMessage(messageID);
    }

    public override void WillSendDataMessage(string messageID, NSError error)
    {
        base.WillSendDataMessage(messageID, error);
    }
}

The GCM API have two methods that should be called when the message are in the process of sending to server, DidSendDataMessage and WillSendDataMessage, but those methods are not called.

Can someone give me some tips here ?

Thanks !

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐