如何使用Quickblox在Cordova应用程序中实现推送通知支持

How to implement push notification support in Cordova app using Quickblox?

本文关键字:实现 通知 支持 应用程序 何使用 Quickblox Cordova      更新时间:2023-09-26

为这样一个基本的问题道歉,但我真的找不到任何关于这个主题的信息。

QuickbloxJavascript SDK有一些与推送通知相关的类,我使用chat_history和chat中的警报选项卡启用了它们。然而,我不明白的是如何在前端UI上接收这些通知?

我没有任何代码可以分享,因为我不知道从哪里开始!

任何帮助都将不胜感激,谢谢。

有一些模块可以使用推送:

QB.messages.tokens
QB.messages.subscriptions
QB.messages.events

要订阅推送,你必须做两件事:

  1. 使用QB.messages.tokens创建推送令牌
  2. 使用QB.messages.subscriptions创建订阅

可以在REST API页面中找到其他信息http://quickblox.com/developers/Messages#Typical_use_.D1.81ases

此外,您还必须上传APNS和谷歌API密钥到QuickBlox管理面板。

如果你要为iOS/Android 构建Cordova应用程序,这一切都需要

  1. 您需要对消息进行编码
  2. 你需要确保你的移动应用程序能够理解解码后的消息

例如,

向android发送推送通知qb_user_id:20290(来自我-我的qb_user_id:12121):

function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
    return String.fromCharCode('0x' + p1);
}));
}
function send_push() {
var params = {
    notification_type: 'push',
    push_type: 'gcm',
    user: {ids: [20290]},
    environment: "production", 
    message: b64EncodeUnicode('{"message":"HELLO WORLD","user_id":12121,"device_type":"WEB","message_qb_id":"563a55a44cedaa83885724cf","message_type":"Text","send_status":"BeingProcessed","send_time":1446663588607}')
  };
  QB.messages.events.create(params, function(err, response) {
    if (err) {
      console.log("QB.messages.events.create::error:" +err);
    } else {
      console.log("QB.messages.events.create::response:" + response);
    }
  });
 }

在本例中,移动应用程序正在查找以下格式的消息:{"消息"、"用户id"、"设备类型"、"消息_qb_id"、"信息类型"、《发送状态》、《发送时间》}