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

feat(app): createPushMessage

上级 dd616eec
......@@ -269,7 +269,8 @@ const plugin = [
'invokePushCallback',
'getPushClientId',
'onPushMessage',
'offPushMessage',
'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()
......@@ -121,14 +142,15 @@ function isUniPushOffline (manifestJson) {
const platformOptions = manifestJson['app-plus']
const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs
const unipush = sdkConfigs && sdkConfigs.push && sdkConfigs.push.unipush
return unipush && unipush.offline === true
return unipush && unipush.offline === true
}
module.exports = {
getManifestJson,
parseManifestJson,
getNetworkTimeout,
getH5Options,
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\';'
......@@ -199,4 +199,4 @@ module.exports = {
]
}
}
}
}
......@@ -21,7 +21,8 @@ if (process.env.UNI_INPUT_DIR && process.env.UNI_INPUT_DIR.indexOf('./') === 0)
process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(process.cwd(), defaultInputDir)
const {
getManifestJson,
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
}
// 初始化全局插件对象
......@@ -558,4 +561,4 @@ runByHBuilderX && console.log(uniI18n.__('compiling'))
module.exports = {
manifestPlatformOptions: platformOptions
}
}
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
}
\ No newline at end of file
}
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
}
\ No newline at end of file
}
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.
先完成此消息的编辑!
想要评论请 注册