chenbool
chenbool
  • 发布:2022-06-08 10:22
  • 更新:2022-06-08 10:22
  • 阅读:290

Native.js 实现 unaipp 离线推送

分类:uni-app
<template>  
    <view class="content">  
    <view class="text-area">  
      <button type="primary" size="mini" @tap="pushMsg()">推送</button>  
    </view>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  

            }  
        },  
        onLoad() {  
      // #ifdef APP-PLUS  
      // 获取客户端标识信息  
      // var info = plus.push.getClientInfo();  
      // console.log( JSON.stringify( info ) );  

      // 添加监听从系统消息中心点击某条消息启动应用事件  
      plus.push.addEventListener('click', function(msg){  
            // 分析msg.payload处理业务逻辑   
            console.log( '点击通知栏: ',msg.payload, msg.content, msg.payload.url )  

          setTimeout(() => {  
            uni.navigateTo({  
              url: msg.payload.url  
            });  
          }, 1000);  

      }, false );  

      // #endif  
        },  
        methods: {  
      pushMsg(){  
        plus.nativeUI.toast('推送消息测试')  
        // createMessage  
        var options = {  
          cover:false,  
          // icon: '',  
          // title: '1111',  
          // subtitle: '1111',  
        };  
        plus.push.createMessage('你收到一条新消息', {  
          type: 'LocalMSG',  
          url: '../test/test'  
        }, options);  

        //设置角标  
        plus.runtime.setBadgeNumber(0);  
      }  

        }  
    }  
</script>  

<style>  
    .content {  
        display: flex;  
        flex-direction: column;  
        align-items: center;  
        justify-content: center;  
    }  

    .logo {  
        height: 200rpx;  
        width: 200rpx;  
        margin-top: 200rpx;  
        margin-left: auto;  
        margin-right: auto;  
        margin-bottom: 50rpx;  
    }  

    .text-area {  
        display: flex;  
        justify-content: center;  
    }  

    .title {  
        font-size: 36rpx;  
        color: #8f8f94;  
    }  
</style>  
0 关注 分享

要回复文章请先登录注册