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

fix(push): getPushClientId

上级 66e14eff
......@@ -2,6 +2,7 @@ import { defineAsyncApi } from '../../helpers/api'
interface OnPushEnabledCallback {
type: 'enabled'
offline: boolean
}
interface OnPushClientIdCallback {
......@@ -28,6 +29,7 @@ interface OnPushClickCallback {
let cid: string | undefined
let cidErrMsg: string | undefined
let enabled: boolean | undefined
let offline: boolean | undefined
function normalizePushMessage(message: unknown) {
try {
......@@ -49,6 +51,9 @@ export function invokePushCallback(
) {
if (args.type === 'enabled') {
enabled = true
if (__PLATFORM__ === 'app') {
offline = args.offline
}
} else if (args.type === 'clientId') {
cid = args.cid
cidErrMsg = args.errMsg
......@@ -89,6 +94,18 @@ const API_GET_PUSH_CLIENT_ID = 'getPushClientId'
export const getPushClientId = defineAsyncApi(
API_GET_PUSH_CLIENT_ID,
(_, { resolve, reject }) => {
// App 端且启用离线时,使用 getClientInfoAsync 来调用
if (__PLATFORM__ === 'app' && offline) {
plus.push.getClientInfoAsync(
(info) => {
resolve({ cid: info.clientid })
},
(res) => {
reject(res.code + ': ' + res.message)
}
)
return
}
Promise.resolve().then(() => {
if (typeof enabled === 'undefined') {
enabled = false
......
......@@ -11075,6 +11075,7 @@ const getLaunchOptionsSync = defineSyncApi(API_GET_LAUNCH_OPTIONS_SYNC, () => {
let cid;
let cidErrMsg;
let enabled;
let offline;
function normalizePushMessage(message) {
try {
return JSON.parse(message);
......@@ -11089,6 +11090,9 @@ function normalizePushMessage(message) {
function invokePushCallback(args) {
if (args.type === 'enabled') {
enabled = true;
{
offline = args.offline;
}
}
else if (args.type === 'clientId') {
cid = args.cid;
......@@ -11127,6 +11131,15 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
}
const API_GET_PUSH_CLIENT_ID = 'getPushClientId';
const getPushClientId = defineAsyncApi(API_GET_PUSH_CLIENT_ID, (_, { resolve, reject }) => {
// App 端且启用离线时,使用 getClientInfoAsync 来调用
if (offline) {
plus.push.getClientInfoAsync((info) => {
resolve({ cid: info.clientid });
}, (res) => {
reject(res.code + ': ' + res.message);
});
return;
}
Promise.resolve().then(() => {
if (typeof enabled === 'undefined') {
enabled = false;
......
// @ts-expect-error
uni.invokePushCallback({
type: 'enabled',
offline: true,
});
Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false);
plus.push.getClientInfoAsync((info) => {
if (info.clientid) {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: info.clientid,
});
}
}, (res) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: '',
errMsg: res.code + ': ' + res.message,
});
});
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
......
// @ts-expect-error
uni.invokePushCallback({
type: 'enabled',
offline: true,
})
Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false)
plus.push.getClientInfoAsync(
(info) => {
if (info.clientid) {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: info.clientid,
})
}
},
(res) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: '',
errMsg: res.code + ': ' + res.message,
})
}
)
plus.push.addEventListener('click', (result) => {
// @ts-expect-error
uni.invokePushCallback({
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册