In my viewdidload method for the SplashViewController.m I create a session with this code
updated this part
QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
extendedAuthRequest.userLogin = @"Login";
extendedAuthRequest.userPassword = @"password";
// QuickBlox session creation
[QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self];
In my ChatViewController.m I subscribe to push notifications with this 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]){
// Now you can receive Push Notifications!
}
}else{
NSLog(@"errors=%@", result.errors);
}
if(result.success && [result isKindOfClass:QBMSendPushTaskResult.class]){
// You have successfully send push notifications
}else{
NSLog(@"errors=%@", result.errors);
}
}
in the sendMessage action I attempt to send a push notification whenever the button is pressed with this code
// send push notification from 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 to users with id 1242713
[QBMessages TSendPush:message toUsers:@"1242713" delegate:nil];
This is the log I get from when I hit the send button in the 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. At least one user should be subscribed for APNS (Apple Push) (through SDK or REST API)</error>
</errors>
Please show the log of this query
[QBMessages TRegisterSubscriptionWithDelegate:self];
If you got success result here - this user should be able to receive push notifications
If you are getting
No recipients. At least one user should be subscribed for APNS (Apple Push) (through SDK or REST API)
it means that user with ID 1242713 didn't do QBMessages TRegisterSubscriptionWithDelegate:self]; or did but result wasn't success
And if you use QuickBlox - you don't need next line:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
TRegisterSubscriptionWithDelegate does it automatically