route.ts 606 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1 2 3 4 5 6 7 8 9 10 11
export 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) => {
12 13 14 15 16
      if (
        res.type === 'receive' &&
        res.data &&
        (res.data as any).force_notification
      ) {
fxy060608's avatar
fxy060608 已提交
17 18 19 20
        // 创建通知栏
        uni.createPushMessage(res.data)
        // 阻止其他监听器继续监听
        ;(res as any).stopped = true
fxy060608's avatar
fxy060608 已提交
21
      }
fxy060608's avatar
fxy060608 已提交
22 23
    })
  }
fxy060608's avatar
fxy060608 已提交
24
}