Quickblox - 如何将通知推送到Android和iOS平台?

时间:2016-05-18 09:16:01

标签: android push-notification quickblox

QBEvent是Quickblox提供的用于支持推送通知的类。 在Android平台上,我必须设置qbEvent.setPushType(QBPushType.GCM)以在多个Android设备之间推送消息。

问题是我想推送Android和iOS的消息,但我可以将这些行设置在一起。 qbEvent.setPushType(QBPushType.GCM)qbEvent.setPushType(QBPushType.APNS)。对此有任何解决方案,请帮忙吗?

enter image description here

1 个答案:

答案 0 :(得分:4)

如果要向所有平台发送推送,则无需传递推送类型参数

解决方案N1(仅限文字):

    QBEvent event = new QBEvent();
    event.setUserIds(userIds);
    event.setType(QBEventType.ONE_SHOT);
    event.setEnvironment(QBEnvironment.DEVELOPMENT);
    event.setNotificationType(QBNotificationType.PUSH);
    //
    event.setMessage("This is simple generic push notification!");

解决方案N2(使用自定义参数):

    QBEvent event = new QBEvent();
    event.setUserIds(userIds);
    event.setType(QBEventType.ONE_SHOT);
    event.setEnvironment(QBEnvironment.DEVELOPMENT);
    event.setNotificationType(QBNotificationType.PUSH);
    //
    // generic push with custom parameters - http://quickblox.com/developers/Messages#Use_custom_parameters
    JSONObject json = new JSONObject();
    try {
      json.put("message", "This is generic push notification with custom params!");
      json.put("param1", "value1");
      json.put("ios_badge", "4"); // iOS badge value
    } catch (Exception e) {
      e.printStackTrace();
    }
    event.setMessage(json.toString());

推送通知摘要中的更多示例 https://github.com/QuickBlox/quickblox-android-sdk/blob/master/snippets/src/main/java/com/sdk/snippets/modules/SnippetsPushNotifications.java#L217

并在文档中 http://quickblox.com/developers/SimpleSample-messages_users-android#Universal_push_notifications