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

feat(app): createPushMessage

上级 dd616eec
......@@ -270,6 +270,7 @@ const plugin = [
'getPushClientId',
'onPushMessage',
'offPushMessage',
'createPushMessage'
]
const apis = [
......
const path = require('path')
const {
hasOwn
} = require('./util')
const {
getJson,
......@@ -98,6 +101,24 @@ function getH5Options (manifestJson) {
return h5
}
function isEnableUniPushV1 (manifestJson, platform) {
if (!manifestJson) {
manifestJson = getManifestJson()
}
if (isEnableUniPushV2(manifestJson, platform)) {
return false
}
if (platform === 'app-plus') {
const platformOptions = manifestJson[platform]
const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs
const push = sdkConfigs && sdkConfigs.push
if (push && hasOwn(push, 'unipush')) {
return true
}
}
return false
}
function isEnableUniPushV2 (manifestJson, platform) {
if (!manifestJson) {
manifestJson = getManifestJson()
......@@ -129,6 +150,7 @@ module.exports = {
parseManifestJson,
getNetworkTimeout,
getH5Options,
isEnableUniPushV1,
isEnableUniPushV2,
isUniPushOffline
}
......@@ -168,7 +168,7 @@ module.exports = {
: 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
},
getPlatformPush () {
if (process.env.UNI_PUSH_V2_OFFLINE) {
if (process.env.UNI_PUSH_V2_OFFLINE || process.env.UNI_PUSH_V1) {
return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js\';'
} else if (process.env.UNI_PUSH_V2) {
return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js\';'
......
......@@ -22,6 +22,7 @@ process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(process.cw
const {
getManifestJson,
isEnableUniPushV1,
isEnableUniPushV2,
isUniPushOffline
} = require('@dcloudio/uni-cli-shared/lib/manifest')
......@@ -47,6 +48,8 @@ if (isEnableUniPushV2(manifestJsonObj, process.env.UNI_PLATFORM)) {
if (process.env.UNI_PLATFORM === 'app-plus' && isUniPushOffline(manifestJsonObj)) {
process.env.UNI_PUSH_V2_OFFLINE = true
}
} else if (isEnableUniPushV1(manifestJsonObj, process.env.UNI_PLATFORM)) {
process.env.UNI_PUSH_V1 = true
}
// 初始化全局插件对象
......
export function getAppAuthorizeSetting() {
export function getAppAuthorizeSetting () {
const { getAppAuthorizeSetting } = weex.requireModule('plus')
let appAuthorizeSetting = getAppAuthorizeSetting()
try {
if (typeof appAuthorizeSetting === 'string')
appAuthorizeSetting = JSON.parse(appAuthorizeSetting)
if (typeof appAuthorizeSetting === 'string') { appAuthorizeSetting = JSON.parse(appAuthorizeSetting) }
} catch (error) { }
return appAuthorizeSetting
......
export function getSystemSetting() {
export function getSystemSetting () {
const { getSystemSetting } = weex.requireModule('plus')
let systemSetting = getSystemSetting()
try {
if (typeof systemSetting === 'string')
systemSetting = JSON.parse(systemSetting)
if (typeof systemSetting === 'string') { systemSetting = JSON.parse(systemSetting) }
} catch (error) { }
return systemSetting
......
import {
hasOwn
} from 'uni-shared'
import {
invoke,
publish
} from '../../bridge'
import {
getAppAuthorizeSetting
} from '../device/get-app-authorize-setting'
let onPushing
let isListening = false
......@@ -63,3 +69,24 @@ export function offPush (params) {
errMsg: 'offPush:ok'
}
}
export function createPushMessage (params, callbackId) {
const setting = getAppAuthorizeSetting()
if (!hasOwn(setting, 'notificationAuthorized')) {
return invoke(callbackId, {
errMsg: 'createPushMessage:fail missing push module'
})
}
if (setting.notificationAuthorized !== 'authorized') {
return invoke(callbackId, {
errMsg: 'createPushMessage:fail ' + setting.notificationAuthorized
})
}
const options = Object.assign({}, params)
delete options.content
delete options.payload
plus.push.createMessage(params.content, params.payload, options)
invoke(callbackId, {
errMsg: 'createPushMessage:ok'
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册