Php 上游消息-iOS GCM

Php 上游消息-iOS GCM,php,ios,xamarin.ios,google-cloud-messaging,Php,Ios,Xamarin.ios,Google Cloud Messaging,我正在尝试在我的应用程序和服务器中使用Google Messaging。应用程序的下游消息服务器工作得很好,但我无法让上游工作 在服务器端,我将PHP与XMPP库JAXL一起使用,通过它,我可以在GCM服务器上进行身份验证并向设备发送消息。我已注册接收具有以下代码的邮件: $XMPPClient->add_cb("on__message", function($stanza){ echo "new message"; $data = json_decod

我正在尝试在我的应用程序和服务器中使用Google Messaging。应用程序的下游消息服务器工作得很好,但我无法让上游工作

在服务器端,我将PHP与XMPP库JAXL一起使用,通过它,我可以在GCM服务器上进行身份验证并向设备发送消息。我已注册接收具有以下代码的邮件:

$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;
        ...
        });
在客户端,我正在使用GCM api调用SendMessage:

GCM API有两个方法,当消息正在发送到服务器时,应该调用这两个方法:DidSendDataMessage和WillSendDataMessage,但这些方法不被调用

有人能给我一些提示吗

谢谢

我发现了问题所在。 首先,您需要将GoogleMessaging.Config的de-delegate设置为从ReceiverDelegate继承的类,而不是从GoogleInstanceID.Config继承的类

之后,您需要从两个库(GoogleMessaging.Service和Google.InstanceID)调用Start方法。然后魔术就完成了:

        private void StartService()
    {
        NSError ConfigError;
        Google.Core.Context.SharedInstance.Configure(out ConfigError);
        GCMSenderID = Google.Core.Context.SharedInstance.Configuration.GcmSenderID;

        SendC = new SendClass();
        Google.GoogleCloudMessaging.Config Conf = Google.GoogleCloudMessaging.Config.DefaultConfig;
        Conf.ReceiverDelegate = SendC;

        Service.SharedInstance.Start(Conf);
        Service.SharedInstance.Connect(delegate (NSError error)
        {
            if (error == null)
            {
                GetToken();
            }
        });
    }

    private void GetToken()
    {
        InstanceId.SharedInstance.Start(Google.InstanceID.Config.DefaultConfig);
        InstanceId.SharedInstance.Token(GCMSenderID, Constants.ScopeGCM, new NSDictionary(Constants.RegisterAPNSOption, DevToken,
            Constants.APNSServerTypeSandboxOption, 1), delegate (string Token, NSError error)
            {
                if (Token != null)
                {
                    OnTokenReceived(Token);
                }
            });
    }
        private void StartService()
    {
        NSError ConfigError;
        Google.Core.Context.SharedInstance.Configure(out ConfigError);
        GCMSenderID = Google.Core.Context.SharedInstance.Configuration.GcmSenderID;

        SendC = new SendClass();
        Google.GoogleCloudMessaging.Config Conf = Google.GoogleCloudMessaging.Config.DefaultConfig;
        Conf.ReceiverDelegate = SendC;

        Service.SharedInstance.Start(Conf);
        Service.SharedInstance.Connect(delegate (NSError error)
        {
            if (error == null)
            {
                GetToken();
            }
        });
    }

    private void GetToken()
    {
        InstanceId.SharedInstance.Start(Google.InstanceID.Config.DefaultConfig);
        InstanceId.SharedInstance.Token(GCMSenderID, Constants.ScopeGCM, new NSDictionary(Constants.RegisterAPNSOption, DevToken,
            Constants.APNSServerTypeSandboxOption, 1), delegate (string Token, NSError error)
            {
                if (Token != null)
                {
                    OnTokenReceived(Token);
                }
            });
    }