1

notification screenshot on IOS Hi I have been trying to send push-notification from android to ios with custom parameters required for my app. Tried sending it as hashmap as in the code above but did not receive that notification at all instead received default notification as :"you have 1 unread message".Also tried sending it as json(Please refer code ) but it goes as plain text and is displayed as json text in the notification to user as shown in the screen shot attached. Please help me with this so i can send notification with only "message" part displayed to user and other custom parameters to be used internally by app.

    StringifyArrayList<Integer> userIds = new StringifyArrayList<Integer>();
    userIds.add(userId1);

    QBEvent event = new QBEvent();
    event.setUserIds(userIds);

    event.setEnvironment(QBEnvironment.DEVELOPMENT);
    event.setNotificationType(QBNotificationType.PUSH);
    event.setPushType(QBPushType.APNS);

    JSONObject json = new JSONObject();
    JSONObject json1 = new JSONObject();
    try {
        // standart parameters

        json.put("text", message);

        // custom parameters
        json1.put("sellerName", sellerName);
        json1.put("Buyer Name", buyerName);
        json1.put("Type",type);

        json.put("custom",json1 );

    } catch (Exception e) {
        e.printStackTrace();
    }
  //HashMap<String, Object> data = new HashMap<String, Object>();
    //data.put("message", message);
   // data.put("sellerName",sellerName);
    //data.put("Type", type);
    //event.setMessage(data);
    event.setMessage(json.toString());


    QBPushNotifications.createEvent(event).performAsync(new QBEntityCallback<QBEvent>() {
        @Override
        public void onSuccess(QBEvent qbEvent, Bundle bundle) {

            System.out.println("QBPush Message success"+qbEvent.getMessage());
        }

        @Override
        public void onError(QBResponseException e) {
          //  System.out.println(" QB Error in Push Message success");
            e.printStackTrace();

        }
    });
Kavya
  • 11
  • 2

1 Answers1

0

If you need to send the universal push notification (the one that goes to all platforms, not only iOS or Android) then you need to omit PushType:

event.setPushType(QBPushType.APNS);

From doc:

https://quickblox.com/developers/Messages#Create_event

event[push_type]:

  • If not present - Notification will be delivered to all possible devices for specified users.
  • If specified - Notification will be delivered to specified platform only

You can refer push notifications code sample page to receive more code snippets (Universal push notifications -> With custom parameters): https://quickblox.com/developers/SimpleSample-messages_users-android#Universal_push_notifications

Rubycon
  • 18,156
  • 10
  • 49
  • 70
  • Thanks for the response, but when I remove the event.setPushType(QBPushType.APNS) the createEvent method throws error :com.quickblox.core.exception.QBResponseException: No one can receive the message at com.quickblox.core.parser.QBJsonParser.parse(SourceFile:89) – Kavya Mar 27 '17 at 09:40
  • and either way i need to send push notification specifically to IOS. The problem Im facing is that When I receive the notification on ios it does not split the message part alone and show in notification text and keep the custom json params in dictionary .how do I achieve this ? please suggest. – Kavya Mar 27 '17 at 09:47