提交 e1680fb3 编写于 作者: fxy060608's avatar fxy060608

fix(app): onPushMessage

上级 08d3d69f
......@@ -100,6 +100,26 @@ e?.onClose(t);
var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMin);
function initPushNotification() {
// 仅 App 端
if (typeof plus !== 'undefined' && plus.push) {
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'click',
message: result,
});
});
uni.onPushMessage((res) => {
if (res.type === 'receive' && res.data && res.data.force_notification) {
// 创建通知栏
uni.createPushMessage(res.data);
res.stopped = true;
}
});
}
}
// if (process.env.UNI_PUSH_DEBUG) {
// GtPush.setDebugMode(true)
// }
......@@ -119,6 +139,7 @@ if (!appid) {
});
}
else {
initPushNotification();
GtPush.init({
appid,
onError: (res) => {
......
......@@ -27,12 +27,18 @@ export function invokePushCallback (
cidErrMsg = args.errMsg
invokeGetPushCidCallbacks(cid, args.errMsg)
} else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({
type: 'receive',
data: normalizePushMessage(args.message)
})
})
const message = {
type: 'receive',
data: normalizePushMessage(args.message)
}
for (let i = 0; i < onPushMessageCallbacks.length; i++) {
const callback = onPushMessageCallbacks[i]
callback(message)
// 该消息已被阻止
if (message.stopped) {
break
}
}
} else if (args.type === 'click') {
onPushMessageCallbacks.forEach((callback) => {
callback({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册