push.ts 820 字节
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import { extend } from '@vue/shared'
fxy060608's avatar
fxy060608 已提交
2 3 4 5 6 7 8 9 10 11 12 13
import {
  API_CREATE_PUSH_MESSAGE,
  API_TYPE_CREATE_PUSH_MESSAGE,
  CreatePushMessageOptions,
  defineAsyncApi,
} from '@dcloudio/uni-api'
import { getAppAuthorizeSetting } from '../device/getAppAuthorizeSetting'
export const createPushMessage = defineAsyncApi<API_TYPE_CREATE_PUSH_MESSAGE>(
  API_CREATE_PUSH_MESSAGE,
  (opts, { resolve, reject }) => {
    const setting = getAppAuthorizeSetting()
    if (setting.notificationAuthorized !== 'authorized') {
fxy060608's avatar
fxy060608 已提交
14
      return reject(`notificationAuthorized: ` + setting.notificationAuthorized)
fxy060608's avatar
fxy060608 已提交
15 16 17 18 19 20 21 22 23 24
    }
    const options = extend({}, opts)
    delete (options as any).content
    delete options.payload
    plus.push.createMessage(opts.content, opts.payload as string, options)
    resolve()
  },
  undefined,
  CreatePushMessageOptions
)