|
1 | 1 | <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> |
18 | 15 | </view> |
19 | 16 | </view> |
20 | 17 | </template> |
|
44 | 41 | this.tranMsg = '' |
45 | 42 | }, |
46 | 43 | 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 | | - }, |
67 | 44 | 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 | + }) |
94 | 56 | }, |
95 | 57 | requireTranMsg() { //请求‘透传数据’推送消息 |
96 | 58 | var inf = plus.push.getClientInfo(); |
|
116 | 78 |
|
117 | 79 | <style> |
118 | 80 |
|
119 | | -</style> |
120 | | - |
| 81 | +</style> |
0 commit comments