php - Upstream message - iOS GCM -


i'm trying implement google messaging in app , server using xamarin api. downstream messages (server app) working great, can't upstream working.

at server side i'm using php xmpp library (jaxl), can auth @ gcm server , send messages devices. i've registered receive messages 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 sent         $gcmkey = $data['from']; //gcm key;         ...         }); 

at client, i'm using 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 2 methods should called when message in process of sending server, didsenddatamessage , willsenddatamessage, methods not called.

can give me tips here ?

thanks !

i've found problems. first need set de delegate of googlemessanging.config class (that inherits receiverdelegate), attention not googleinstanceid.config.

after that, need call method start() 2 libraries,googlemessaging.service , google.instanceid. magic done:

        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);                 }             });     } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -