【问题标题】:PushNotification with custom parameter from android to IOS goes as just text带有从 android 到 IOS 的自定义参数的 PushNotification 只是文本
【发布时间】:2017-08-13 01:43:50
【问题描述】:

notification screenshot on IOS Hi 我一直在尝试使用我的应用程序所需的自定义参数将推送通知从 android 发送到 ios。尝试像上面的代码一样将其作为哈希图发送,但根本没有收到该通知,而是收到默认通知:“您有 1 条未读消息”。还尝试将其作为 json 发送(请参考代码),但它以纯文本形式发送,并且如附加的屏幕截图所示,在给用户的通知中显示为 json 文本。请帮我解决这个问题,这样我就可以发送通知,其中仅向用户显示“消息”部分以及应用程序内部使用的其他自定义参数。

    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();

        }
    });

【问题讨论】:

    标签: push-notification quickblox quickblox-android


    【解决方案1】:

    如果您需要发送通用推送通知(适用于所有平台的推送通知,不仅适用于 iOS 或 Android),那么您需要省略 PushType:

    event.setPushType(QBPushType.APNS);
    

    来自文档:

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

    事件[push_type]:

    • 如果不存在 - 通知将发送给所有可能的人 指定用户的设备。
    • 如果指定 - 通知将仅发送到指定平台

    您可以参考推送通知代码示例页面以接收更多代码sn-ps(通用推送通知->带有自定义参数):https://quickblox.com/developers/SimpleSample-messages_users-android#Universal_push_notifications

    【讨论】:

    • 感谢您的回复,但是当我删除 event.setPushType(QBPushType.APNS) 时,createEvent 方法会抛出错误:com.quickblox.core.exception.QBResponseException: No one can receive the message at com .quickblox.core.parser.QBJsonParser.parse(SourceFile:89)
    • 无论哪种方式,我都需要专门向 IOS 发送推送通知。我面临的问题是,当我在 ios 上收到通知时,它不会单独拆分消息部分并显示在通知文本中并将自定义 json 参数保留在字典中。我该如何实现?请提出建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多