ios - Quickblox: "No recipient" error. Trying to add push notification messages to Simple Chat -
in viewdidload method splashviewcontroller.m create session code
updated part
qbasessioncreationrequest *extendedauthrequest = [qbasessioncreationrequest request]; extendedauthrequest.userlogin = @"login"; extendedauthrequest.userpassword = @"password"; // quickblox session creation [qbauth createsessionwithextendedrequest:extendedauthrequest delegate:self];
in chatviewcontroller.m subscribe push notifications bit of code
// quickblox api queries delegate - (void)completedwithresult:(result *)result{ // quickblox session creation result if([result iskindofclass:[qbaauthsessioncreationresult class]]){ // success result if(result.success){ [qbmessages tregistersubscriptionwithdelegate:self]; double delayinseconds = 1.0; dispatch_time_t poptime = dispatch_time(dispatch_time_now, (int64_t)(delayinseconds * nsec_per_sec)); dispatch_after(poptime, dispatch_get_main_queue(), ^(void){ // hide splash [self dismissviewcontrolleranimated:yes completion:nil]; [[nsnotificationcenter defaultcenter] postnotificationname:kuserloggedinnotification object:nil]; }); }else if([result iskindofclass:qbmregistersubscriptiontaskresult.class]){ // can receive push notifications! } }else{ nslog(@"errors=%@", result.errors); } if(result.success && [result iskindofclass:qbmsendpushtaskresult.class]){ // have send push notifications }else{ nslog(@"errors=%@", result.errors); } }
in sendmessage action attempt send push notification whenever button pressed code
// send push notification app nsstring *mesage = @"hello man!"; nsmutabledictionary *payload = [nsmutabledictionary dictionary]; nsmutabledictionary *aps = [nsmutabledictionary dictionary]; [aps setobject:@"default" forkey:qbmpushmessagesoundkey]; [aps setobject:mesage forkey:qbmpushmessagealertkey]; [payload setobject:aps forkey:qbmpushmessageapskey]; qbmpushmessage *message = [[qbmpushmessage alloc] initwithpayload:payload]; // send push users id 1242713 [qbmessages tsendpush:message tousers:@"1242713" delegate:nil];
this log when hit send button in chatviewcontroller
2014-06-27 13:09:54.871 sample-chat[10607:143f] -[qbchat xmppstream:didsendpresence:] -> presence: <presence/> 2014-06-27 13:10:05.758 sample-chat[10607:143f] -[qbchat xmppstream:didsendmessage:] -> message: <message id="4" type="chat" to="1242713-11606@chat.quickblox.com" from="1242638-11606@chat.quickblox.com"><body>test</body></message> 2014-06-27 13:10:05.759 sample-chat[10607:143f] +[qbmevent messagetostring:] -> message: { payload = "{\"aps\":{\"sound\":\"default\",\"alert\":\"hello man!\"}}"; } 2014-06-27 13:10:05.759 sample-chat[10607:143f] performing async request: post https://api.quickblox.com/events.xml headers:{ "qb-sdk" = "ios 1.8.6"; "qb-token" = 84cc16b1fa6486d9443dcaecff84f10b380fe24c; "quickblox-rest-api-version" = "0.1.1"; } parameters:{ "event[environment]" = development; "event[event_type]" = "one_shot"; "event[message]" = "payload=eyjhchmionsic291bmqioijkzwzhdwx0iiwiywxlcnqioijizwxsbybtyw4hin19"; "event[notification_type]" = push; "event[push_type]" = apns; "event[user][ids]" = "1242713"; } 2014-06-27 13:10:06.036 sample-chat[10607:652b] request finished, response: headers:{ "access-control-allow-origin" = "*"; "cache-control" = "no-cache"; connection = "keep-alive"; "content-type" = "application/xml; charset=utf-8"; date = "fri, 27 jun 2014 18:10:06 gmt"; "qb-token-expirationdate" = "2014-06-27 20:08:24 utc"; "quickblox-rest-api-version" = "0.1.1"; server = "nginx/1.0.15"; status = "422 unprocessable entity"; "transfer-encoding" = identity; "x-rack-cache" = "invalidate, pass"; "x-request-id" = 7fdb550db4da0d7833bf6391d91c134e; "x-runtime" = "0.024664"; "x-ua-compatible" = "ie=edge,chrome=1"; } body: error: <?xml version="1.0" encoding="utf-8"?> <errors> <error>no recipients. @ least 1 user should subscribed apns (apple push) (through sdk or rest api)</error> </errors>
please show log of query
[qbmessages tregistersubscriptionwithdelegate:self];
if got success result here - user should able receive push notifications
if getting
no recipients. @ least 1 user should subscribed apns (apple push) (through sdk or rest api)
it means user id 1242713 didn't qbmessages tregistersubscriptionwithdelegate:self]; or did result wasn't success
and if use quickblox - don't need next line:
[[uiapplication sharedapplication] registerforremotenotificationtypes:(uiremotenotificationtypebadge | uiremotenotificationtypesound | uiremotenotificationtypealert)];
tregistersubscriptionwithdelegate automatically
Comments
Post a Comment