|
@@ -1,31 +1,45 @@
|
|
|
<script>
|
|
|
+ var AndroidLog = uni.requireNativePlugin("AndroidLog")
|
|
|
+ var device = uni.requireNativePlugin("DeviceInfo")
|
|
|
export default {
|
|
|
onLaunch: function() {
|
|
|
- // console.log('App Launch')
|
|
|
//判断客户端类别
|
|
|
- if (/MicroMessenger/.test(window.navigator.userAgent)) {
|
|
|
- uni.setStorage({
|
|
|
- key:'userAgent',
|
|
|
- data:'wxAgent'
|
|
|
+ const _handlePush = function(message) {
|
|
|
+ // console.log("接收到推送消息:" ,message);
|
|
|
+ // alert(message)
|
|
|
+ AndroidLog.info({message: message})
|
|
|
+ };
|
|
|
+
|
|
|
+ setTimeout(()=>{
|
|
|
+ var pinf = plus.push.getClientInfo();
|
|
|
+ var cid = pinf.clientid;//客户端标识
|
|
|
+ if(cid != null && cid != '' && cid != 'null'){
|
|
|
+ //注册设备
|
|
|
+ var deviceInfo = device.getDeviceInfo()
|
|
|
+ this.$u.api.deviceReg({deviceNo:deviceInfo.deviceId,pushCid: cid})
|
|
|
+ .then(res=>{
|
|
|
+ if (res.code == 200){
|
|
|
+ plus.nativeUI.toast('设备注册成功');
|
|
|
+ }else{
|
|
|
+ plus.nativeUI.toast('设备注册失败');
|
|
|
+ }
|
|
|
+ }).catch(err=>{
|
|
|
+ plus.nativeUI.toast('设备注册失败');
|
|
|
});
|
|
|
- // console.log('handleAliPay 微信客户端');
|
|
|
- } else if (/AlipayClient/.test(window.navigator.userAgent)) {
|
|
|
- uni.setStorage({
|
|
|
- key:'userAgent',
|
|
|
- data:'aliAgent'
|
|
|
- });
|
|
|
- // console.log('handleAliPay 支付宝客户端');
|
|
|
- } else {
|
|
|
- uni.setStorage({
|
|
|
- key:'userAgent',
|
|
|
- data:'otherAgent'
|
|
|
- });
|
|
|
- // console.log('handleAliPay 其他浏览器');
|
|
|
- };
|
|
|
+ clearTimeout()
|
|
|
+ }
|
|
|
+ }, 400);
|
|
|
+
|
|
|
+ //监听系统通知栏消息点击事件
|
|
|
+ plus.push.addEventListener('click', _handlePush,false);
|
|
|
+
|
|
|
+ //监听接收透传消息事件
|
|
|
+ plus.push.addEventListener('receive', _handlePush,false);
|
|
|
// this.$wxApi.config();
|
|
|
},
|
|
|
onShow: function() {
|
|
|
// console.log('App Show')
|
|
|
+
|
|
|
},
|
|
|
onHide: function() {
|
|
|
// console.log('App Hide')
|