0

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>
mostly
  • 29
  • 7

2 Answers2

0

I'm just guessing with the error log, have you registered your app for push notifications in AppDelegate i.e :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
]

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{

    NSString *str = [NSString stringWithFormat:@"My token is: %@", deviceToken];
}
HaneTV
  • 916
  • 1
  • 7
  • 24
  • I updated my question to show my entire viewdidload method. I added the line `[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];` but am still getting the same error. I'm not sure where or how to implement the `didRegisterForRemoteNotificationsWithDeviceToken` method without getting the error of *str being an unused variable. Were you suggesting I use NSLog to find out what it's sending maybe? – mostly Jun 28 '14 at 01:19
  • yup, is deviceToken a valid token? – HaneTV Jun 29 '14 at 21:42
  • ya, on line 110 of this log it shows a valid token https://gist.github.com/anonymous/ddcd267d933d61c79b93 Do you have a site btw or an app that deals with video stuff? I was reading your answers and you look like youre very knowledgable in the space – mostly Jul 03 '14 at 05:38
  • Did you watched [here](http://stackoverflow.com/questions/21651421/quickblox-not-sending-apns) ? It seems related. And yes, I made a real time streaming app named Mobelive (app store). It's in french but translation is on the way :) – HaneTV Jul 03 '14 at 07:33
  • Your app looks really cool! Definitely looking forward to trying out the english version. Thanks for the link. I found that the UDID registered to my user doesn't match my device's UDID that I checked in iTunes. This is odd because I am still able to receive push notifications from the admin panel that are sent to my device. – mostly Jul 03 '14 at 10:23
  • Did you build Mobelive by yourself? – mostly Jul 03 '14 at 19:06
  • Wow that's impressive, must have taken a LOT of work! I'm gonna shoot an email to hello@mobelive.com and when the english version is released I'll promote it to my friends for sure. also thanks for the help with this question. your advice helped me along the way. – mostly Jul 04 '14 at 07:33
0

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

Rubycon
  • 18,156
  • 10
  • 49
  • 70
  • log for when I run the app from my developer device https://gist.github.com/anonymous/ddcd267d933d61c79b93. The QBMessages error log is on line 106. I added this line after the QBMessages subscription to generate the log `NSLog(@"QBMessages errors=%@", result.errors);` When I run the app from simulator i get this log https://gist.github.com/anonymous/0f3a92beb69ca5e081ff which complains `At least one user should be subscribed for APNS` I'm trying to test if one user can send a push notification to another user. Can I not receive push notifications sent from the simulator to my device? – mostly Jul 03 '14 at 05:24
  • I am able to receive push notifications from the admin panel, I just can't receive them when I use the api within the app sent from the simulator to my device. On my device I login to the account that has user id "1242713" – mostly Jul 03 '14 at 05:58
  • When i receive push notifications from the admin panel I don't even have to be logged in to the chat app on my device to receive them, I just have to have the app on in the background. – mostly Jul 03 '14 at 16:47
  • I almost have it working. My main issue was that I was trying to create a session with this code `extendedAuthRequest.userLogin = [[QBUUser user]login]; extendedAuthRequest.userPassword = [[QBUUser user ]password];` I changed the login and password fields to match a single user that I made from the admin panel with @"login" and @"password". Instead of using `[[QBUUser user]login]` to login, what should I use to subscribe a user that logs in with twitter or fb? – mostly Jul 03 '14 at 18:25
  • In the login controller under the completedWithResult method i used `extendedAuthRequest.userLogin = [LocalStorageService shared].currentUser.login; extendedAuthRequest.userPassword = [LocalStorageService shared].currentUser.password;` to log the user in and it seems to be working. Is this the right way Igor? – mostly Jul 04 '14 at 04:11