Skip to content

Commit c1e54dc

Browse files
committed
update: push.vue
1 parent e3cb098 commit c1e54dc

File tree

1 file changed

+25
-64
lines changed

1 file changed

+25
-64
lines changed

platforms/app-plus/push/push.vue

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<template>
2-
<view>
3-
<page-head :title="title"></page-head>
4-
<view class="uni-padding-wrap" v-if="provider[0]">
5-
<view class="uni-btn-v uni-common-mt">
6-
<button type="primary" @tap="openPush">开启push</button>
7-
<button type="primary" @tap="closePush">关闭push</button>
8-
<button type="primary" @tap="listenTranMsg">监听透传数据</button>
9-
<button type="primary" @tap="removeTranMsg">移除监听透传数据</button>
10-
</view>
11-
<view class="uni-btn-v uni-common-mt">
12-
<button type="primary" @tap="requireTranMsg">发送"透传数据"消息</button>
13-
</view>
14-
<view class="uni-title uni-common-mt">透传内容:</view>
15-
<view class="uni-textarea">
16-
<textarea v-model="tranMsg" />
17-
</view>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap" v-if="provider[0]">
5+
<view class="uni-btn-v uni-common-mt">
6+
<button type="primary" @tap="listenTranMsg">监听透传数据</button>
7+
</view>
8+
<view class="uni-btn-v uni-common-mt">
9+
<button type="primary" @tap="requireTranMsg">发送"透传数据"消息</button>
10+
</view>
11+
<view class="uni-title uni-common-mt">透传内容:</view>
12+
<view class="uni-textarea">
13+
<textarea v-model="tranMsg" />
14+
</view>
1815
</view>
1916
</view>
2017
</template>
@@ -44,53 +41,18 @@
4441
this.tranMsg = ''
4542
},
4643
methods: {
47-
openPush() {
48-
uni.subscribePush({
49-
provider: this.provider[0],
50-
success: (e) => {
51-
uni.showToast({
52-
title: "已开启push接收"
53-
})
54-
}
55-
})
56-
},
57-
closePush() {
58-
uni.unsubscribePush({
59-
provider: this.provider[0],
60-
success: (e) => {
61-
uni.showToast({
62-
title: "已关闭push接收"
63-
})
64-
}
65-
})
66-
},
6744
listenTranMsg() {
68-
uni.onPush({
69-
provider: this.provider[0],
70-
success: (e) => {
71-
uni.showToast({
72-
title: "开始监听透传数据"
73-
})
74-
},
75-
callback: (e) => {
76-
uni.showToast({
77-
title: "接收到透传数据"
78-
});
79-
80-
this.tranMsg = JSON.stringify(e.data);
81-
}
82-
})
83-
},
84-
removeTranMsg() {
85-
uni.offPush({
86-
provider: this.provider[0],
87-
success: (e) => {
88-
console.log("移除监听透传数据");
89-
uni.showToast({
90-
title: "移除监听透传数据"
91-
})
92-
}
93-
})
45+
// IOS端在客户端在运行时收到推送消息触发receive事件,离线接收到的推送消息全部进入系统消息中心。点击消息中心的消息触发click
46+
plus.push.addEventListener('click', (msg)=> {
47+
this.tranMsg = JSON.stringify(msg)
48+
});
49+
plus.push.addEventListener('receive',(msg)=>{
50+
this.tranMsg = JSON.stringify(msg)
51+
})
52+
uni.showToast({
53+
title: '开始监听透传数据',
54+
icon: 'success'
55+
})
9456
},
9557
requireTranMsg() { //请求‘透传数据’推送消息
9658
var inf = plus.push.getClientInfo();
@@ -116,5 +78,4 @@
11678

11779
<style>
11880
119-
</style>
120-
81+
</style>

0 commit comments

Comments
 (0)