Search code examples
androidiospush-notificationquickblox

Quickblox universal push notification not working.


I am using quickblox for my application. This application is for android iOS both. I am working on push notification. For that I use this code :

// Send push to users with ids 292,300,1295
    QBMEvent *event = [QBMEvent event];
    event.notificationType = QBMNotificationTypePush;
    event.usersIDs = [NSString stringWithFormat:@"%ld", (long)recepID];
    event.type = QBMEventTypeOneShot;

    // standart parameters
    // read more about parameters formation http://quickblox.com/developers/Messages#Use_custom_parameters
    //
    NSMutableDictionary  *dictPush = [NSMutableDictionary  dictionary];
    [dictPush setObject:@"Message received from Bob" forKey:@"message"];
    [dictPush setObject:@"5" forKey:@"ios_badge"];
    [dictPush setObject:@"mysound.wav" forKey:@"ios_sound"];

    // custom params
    [dictPush setObject:@"234" forKey:@"user_id"];
    [dictPush setObject:@"144" forKey:@"thread_id"];

    NSError *error = nil;
    NSData *sendData = [NSJSONSerialization dataWithJSONObject:dictPush options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:sendData encoding:NSUTF8StringEncoding];
    //
    event.message = jsonString;

    [QBRequest createEvent:event successBlock:^(QBResponse * _Nonnull response, NSArray<QBMEvent *> * _Nullable events)
    {
        // Successful response with event
        NSLog(@"Create event successfully to: %ld", (long)recepID);
    }
                errorBlock:^(QBResponse * _Nonnull response)
    {
        // Handle error
        NSLog(@"Create event error to: %@", response.error.description);
    }];

This create event fails and it shows this error:

Create event error to: 
   Error reasons:{
    errors =     (
        "No one can receive the message"
    );
}

All device are there in subsciptions section. Still It gives error. I copied this code from this quickblox document. Please help me.


Solution

  • Solved it by adding this line in my code :

    event.isDevelopmentEnvironment = ![QBApplication sharedApplication].productionEnvironmentForPushesEnabled;