UniPush消息推送, 安卓ios开箱即用

UniPush消息推送, 安卓ios接收,点击完整版

APP.vue

onLaunch()内

// 获取cid
const that= this;
var info = plus.push.getClientInfo();
console.log('info', JSON.stringify(info));
let osname = plus.os.name;
if (osname == 'Android') {
	uni.onPush({
		provider: 'unipush',
		success: function() {
			console.log('监听透传成功');
		},
		callback: function(data) {
			console.log('接收到透传数据:' + JSON.stringify(data));
			plus.push.createMessage(data.data, {});
		}
	});
}
// 监听在线消息事件
if (osname == 'iOS') {
	plus.push.addEventListener(
		'receive',
		function(msg) {
			let content = JSON.parse(msg.content)
			if(msg.payload != 'LocalMSG') {
				console.log(msg, 'ios', content.content)
				uni.setStorageSync('payload', msg.payload)
				// ios通知显示
				plus.push.createMessage(msg.payload.content, 'LocalMSG', {
					cover: false,
					title: msg.payload.title
				});
			}
		},
		false
	);
}
plus.push.addEventListener(
	'click',
	// 点击消息栏推送消息,执行函数
	function(data) {
		console.log(data.payload, 'data.payload')
		if(data.payload != 'LocalMSG') {
			uni.setStorageSync('payload', data.payload)
		}
		// 点击事件处理函数
		that._handlePush();
	},
	false
);
// 在线
plus.push.addEventListener(
	'receive',
	function(res) {
		if (osname == 'Android') {
			console.log(res);
			if(res.payload != 'LocalMSG') {
				uni.setStorageSync('payload', res.payload)
			}
			var options = { cover: false, title: res.title, content: res.content };
			plus.push.createMessage(res.content, res.payload, options);
		}
	},
	false
);

在线推送通知闪退: createMessage(),第一个参数为String且不能为空

上一篇:vueAdmin动态路由


下一篇:Bert和一些以Bert为基础的预训练模型的Mask区别