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

feat(app): createPushMessage

上级 dd616eec
...@@ -269,7 +269,8 @@ const plugin = [ ...@@ -269,7 +269,8 @@ const plugin = [
'invokePushCallback', 'invokePushCallback',
'getPushClientId', 'getPushClientId',
'onPushMessage', 'onPushMessage',
'offPushMessage', 'offPushMessage',
'createPushMessage'
] ]
const apis = [ const apis = [
......
const path = require('path') const path = require('path')
const {
hasOwn
} = require('./util')
const { const {
getJson, getJson,
...@@ -98,6 +101,24 @@ function getH5Options (manifestJson) { ...@@ -98,6 +101,24 @@ function getH5Options (manifestJson) {
return h5 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) { function isEnableUniPushV2 (manifestJson, platform) {
if (!manifestJson) { if (!manifestJson) {
manifestJson = getManifestJson() manifestJson = getManifestJson()
...@@ -121,14 +142,15 @@ function isUniPushOffline (manifestJson) { ...@@ -121,14 +142,15 @@ function isUniPushOffline (manifestJson) {
const platformOptions = manifestJson['app-plus'] const platformOptions = manifestJson['app-plus']
const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs const sdkConfigs = platformOptions && platformOptions.distribute && platformOptions.distribute.sdkConfigs
const unipush = sdkConfigs && sdkConfigs.push && sdkConfigs.push.unipush const unipush = sdkConfigs && sdkConfigs.push && sdkConfigs.push.unipush
return unipush && unipush.offline === true return unipush && unipush.offline === true
} }
module.exports = { module.exports = {
getManifestJson, getManifestJson,
parseManifestJson, parseManifestJson,
getNetworkTimeout, getNetworkTimeout,
getH5Options, getH5Options,
isEnableUniPushV1,
isEnableUniPushV2, isEnableUniPushV2,
isUniPushOffline isUniPushOffline
} }
...@@ -168,7 +168,7 @@ module.exports = { ...@@ -168,7 +168,7 @@ module.exports = {
: 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';' : 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
}, },
getPlatformPush () { 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\';' return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.plus.es.js\';'
} else if (process.env.UNI_PUSH_V2) { } else if (process.env.UNI_PUSH_V2) {
return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js\';' return ';import \'@dcloudio/vue-cli-plugin-uni/packages/uni-push/dist/uni-push.es.js\';'
...@@ -199,4 +199,4 @@ module.exports = { ...@@ -199,4 +199,4 @@ module.exports = {
] ]
} }
} }
} }
...@@ -21,7 +21,8 @@ if (process.env.UNI_INPUT_DIR && process.env.UNI_INPUT_DIR.indexOf('./') === 0) ...@@ -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) process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(process.cwd(), defaultInputDir)
const { const {
getManifestJson, getManifestJson,
isEnableUniPushV1,
isEnableUniPushV2, isEnableUniPushV2,
isUniPushOffline isUniPushOffline
} = require('@dcloudio/uni-cli-shared/lib/manifest') } = require('@dcloudio/uni-cli-shared/lib/manifest')
...@@ -47,6 +48,8 @@ if (isEnableUniPushV2(manifestJsonObj, process.env.UNI_PLATFORM)) { ...@@ -47,6 +48,8 @@ if (isEnableUniPushV2(manifestJsonObj, process.env.UNI_PLATFORM)) {
if (process.env.UNI_PLATFORM === 'app-plus' && isUniPushOffline(manifestJsonObj)) { if (process.env.UNI_PLATFORM === 'app-plus' && isUniPushOffline(manifestJsonObj)) {
process.env.UNI_PUSH_V2_OFFLINE = true 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')) ...@@ -558,4 +561,4 @@ runByHBuilderX && console.log(uniI18n.__('compiling'))
module.exports = { module.exports = {
manifestPlatformOptions: platformOptions manifestPlatformOptions: platformOptions
} }
export function getAppAuthorizeSetting() { export function getAppAuthorizeSetting () {
const { getAppAuthorizeSetting } = weex.requireModule('plus') const { getAppAuthorizeSetting } = weex.requireModule('plus')
let appAuthorizeSetting = getAppAuthorizeSetting() let appAuthorizeSetting = getAppAuthorizeSetting()
try { try {
if (typeof appAuthorizeSetting === 'string') if (typeof appAuthorizeSetting === 'string') { appAuthorizeSetting = JSON.parse(appAuthorizeSetting) }
appAuthorizeSetting = JSON.parse(appAuthorizeSetting)
} catch (error) { } } catch (error) { }
return appAuthorizeSetting return appAuthorizeSetting
} }
\ No newline at end of file
export function getSystemSetting() { export function getSystemSetting () {
const { getSystemSetting } = weex.requireModule('plus') const { getSystemSetting } = weex.requireModule('plus')
let systemSetting = getSystemSetting() let systemSetting = getSystemSetting()
try { try {
if (typeof systemSetting === 'string') if (typeof systemSetting === 'string') { systemSetting = JSON.parse(systemSetting) }
systemSetting = JSON.parse(systemSetting)
} catch (error) { } } catch (error) { }
return systemSetting return systemSetting
} }
\ No newline at end of file
import { import {
hasOwn
} from 'uni-shared'
import {
invoke,
publish publish
} from '../../bridge' } from '../../bridge'
import {
getAppAuthorizeSetting
} from '../device/get-app-authorize-setting'
let onPushing let onPushing
let isListening = false let isListening = false
...@@ -63,3 +69,24 @@ export function offPush (params) { ...@@ -63,3 +69,24 @@ export function offPush (params) {
errMsg: 'offPush:ok' 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.
先完成此消息的编辑!
想要评论请 注册