在app 中几乎都会用到推送,uni-app 提供了 uni push 服务,这是一个包括客户端和服务器的统一服务,整合了苹果APNs、华为、小米、OPPO、VIVO、魅族等多家厂商的推送和个推的独立推送,不管客户端还是服务器,一套代码多端推送。

开发者可以在uniPush中只接入个推,不配置其他厂商服务,但这将导致Android上App离线后无法推送消息。因为现在的国产rom节电管理策略严格,不使用rom厂商的push基本难以离线送达消息。 若想提供消息推送成功率,只有使用uniPush,并向各rom厂商申请开通推送服务(免费)。

下面是uni-app 推送中的两个方法,“click”,"receive"

  //从系统消息中心点击消息启动应用事件plus.push.addEventListener("click", function(msg) {// do something})//应用从推送服务器接收到推送消息事件plus.push.addEventListener("receive", function(msg) {// do something})

看这张图片,大概就能知道其中的处理过程

App.vue 中

onLaunch: function() {if (uni.getSystemInfoSync().platform == "ios") {plus.runtime.setBadgeNumber(0);//导入个推原生类var GeTuiSdk = plus.ios.importClass("GeTuiSdk");GeTuiSdk.setBadge(0);}let that = this;// 锁定屏幕方向plus.screen.lockOrientation("portrait-primary"); //锁定plus.push.addEventListener("click", function(message) {let token = uni.getStorageSync("token");if (typeof token == "undefined" || token == null || token == ""){this.sureLoGin = setInterval(() => {token = uni.getStorageSync("token");if (typeof token != "undefined" && token != null && token != ""){clearInterval(this.sureLoGin);this.sureLoGin = undefined;that.tapClick(message);}}, 300);} else {that.tapClick(message);}});plus.push.addEventListener("receive",function(msg) {if (typeof msg.payload == "string") {msg.payload = JSON.parse(msg.payload);}let body = msg.payload;if (uni.getSystemInfoSync().platform == "ios") {plus.runtime.setBadgeNumber(0);//导入个推原生类var GeTuiSdk = plus.ios.importClass("GeTuiSdk");GeTuiSdk.setBadge(0);}if (typeof body.uuid == "undefined" &&uni.getSystemInfoSync().platform == "ios") {body.uuid = 111;let title = msg.aps.alert.title;let msgbody = msg.aps.alert.body;plus.push.createMessage(title + ":" + msgbody,JSON.stringify(msg.payload));}},false);},

login.vue 中,登录时,把用户的cliengtId发送给后端

onLoad() {let that = this;// setTimeout(() => {uni.getProvider({service: 'push',success: e => {that.provider = e.provider;uni.subscribePush({provider: that.provider[0],success: function(res) {var inf = plus.push.getClientInfo();if (uni.getSystemInfoSync().platform == 'android') {that.clientId = inf.clientid;that.tokenType = 'android';} else if (uni.getSystemInfoSync().platform == 'ios') {that.clientId = inf.token;that.tokenType = 'ios';}uni.onPush({provider: that.provider[0],success: e => {},callback: e => {}});},fail: function(err) { uni.onPush({provider: that.provider[0],success: e => {},callback: e => {}});}});},fail: e => {uni.subscribePush({provider: that.provider[0],success: function(res) {                        uni.onPush({provider: that.provider[0],success: e => {},callback: e => {}});},fail: function(err) {                 uni.onPush({provider: that.provider[0],success: e => {},callback: e => {}});}});}});// }, 1000);let token = uni.getStorageSync('token');let lastFreshTime = uni.getStorageSync('refreshTime');if (lastFreshTime != undefined && lastFreshTime != '') {let username = uni.getStorageSync('username');let password = uni.getStorageSync('password');uni.removeStorageSync('token');uni.showLoading({title: '正在登录...'});this.$request.post('rbac/auth/login', {username: username,password: password,clientId:that.clientId,tokenType:that.tokenType}).then(res => {if (res.code == this.$zscommon.CODE_SUCCESS) {                 uni.setStorageSync('token', res.token); //tokenuni.setStorageSync('refreshTime', new Date().getTime()); //更新token刷新时间uni.hideLoading();//token更新完成后,跳转至首页uni.switchTab({url: '/pages/index/index'});} else {this.$zscommon.toast(res.msg);this.$zscommon.clearUserInfo();//跳回登陆页面uni.reLaunch({url: '../login/login'});}});}},

后台推送消息给app_uni-app 消息推送相关推荐

  1. 关于百度云推送加厂商进行app离线推送的步骤小记

    经过漫长的无所事事,终于来了一个活,要搞推送,不能socket,要后台关闭了也能推. 第三方推送,厂商自带,各种看了一下,但最终产品敲定,用百度云推送 研究的过程都是千篇一律,下demo,看文档,测试 ...

  2. APP消息智能推送有什么特点

    虽然在这个互联网飞速发展的时代,越来越多的APP被安装在用户手机上.但除了一些极其频繁的APP,如微信和淘宝,大多数APP每天都静静地躺在移动桌面的小角落里,被动地等待用户醒来. 要唤醒这些客户,信息 ...

  3. App地推效果差?你可能缺少渠道效果统计

    App推广有线上线下很多种形式.但是由于线上推广的流量成本越来越高,地推成为很多App推广的首选方式.在大多数人的印象里,地推可能还只是一群人在路边发小广告的纯粹人力进行推销的形式. 事实上,现在的地 ...

  4. 有效APP地推的必要性

    当前APP地推行业里的乱象太多,凸显有效APP地推的可贵.坚持做有效APP地推的公司,才能和同行们真正拉开差距,而不是人人都用价格战来拼杀做坏整个行业,甲方更愿意找做有效APP地推公司合作. 为了实现 ...

  5. 极光推送:java后台向APP推送消息(android,ios极光推送消息)

    Maven添加依赖 <!--极光推送--><dependency><groupId>cn.jpush.api</groupId><artifact ...

  6. 如何构建一套高可用的 APP 消息推送平台

    转载自  如何构建一套高可用的 APP 消息推送平台 消息推送作为移动 APP 运营中的一项关键技术,已经被越来越广泛的运用.本文追溯了推送技术的发展历史,剖析了其核心原理,并对推送服务的关键技术进行 ...

  7. 国内APP消息推送机制以及微信消息延迟问题剖析

    转自:https://club.huawei.com/thread-15878044-1-1.html 一.前言 随着安卓手机以及QQ/微信/支付宝/滴滴出行/美图外卖等一大批移动通信/移动消费应用的 ...

  8. APP消息推送测试点

    APP消息推送测试点 2019.03.15 17:38:39 字数 190 阅读 50 消息推送对象 1.单个推送 2.多个推送 3.及安卓和IOS渠道推送 ps: 注意生产环境和测试环境的分开,避免 ...

  9. app消息推送(ios/android)基础知识

    手机推送会遇到存在两种情况: app在界面或后台运行(端内) app从后台被移除(端外) 端内推送 轮询:定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并关闭连接.(适合小型) [h5 ...

  10. unipush+java+个推实现app消息推送

    unipush使用指南:https://ask.dcloud.net.cn/article/35622 首先需要开通unipush, 然后需要获取cid,cid的作用就是标识是哪一个终端,也就是标识a ...

最新文章

  1. C语言项目--教师信息/学生成绩管理系统
  2. 【CI/CD1】jenkins
  3. ubuntu系统下gedit 打开GBK字符集编码文件出现乱码问题解决办法
  4. macos剪切_如何使用macOS的内置“ Kill and Yank”作为替代剪切和粘贴
  5. python gridsearch_python gridsearch中的内存错误
  6. 用例子来区分4种文法
  7. Scalaz(47)- scalaz-stream: 深入了解-Source
  8. android手机内存单位 吉字节,内存容量单位换算(手机内存单位大小排列换算)
  9. 移动端web开发click touch tap区别
  10. 渝粤题库 国家开放大学 学前儿童艺术教育(音乐) 期末考试复习资料
  11. 多元函数式子两端微分
  12. 动画中的“表现手法”和“表现方式”分别是什么?今天艺点动画大家庭来给你唠嗑唠嗑
  13. 服务器虚拟主机玩魔域,服务器虚拟主机玩魔域
  14. 坐标正算和坐标反算的c语言,坐标正算程序坐标反算程序
  15. 桌面支持--PLM软件必须右键用管理员账号打开
  16. CTime 和COleDateTime的常用操作和比较
  17. 首发体验!打自动驾驶出租车感觉如何?
  18. html禁止qq管家弹出广告,教你两招系统自带永久关闭电脑弹窗广告、流氓软件
  19. lisp 标注螺纹孔_英制螺母标注方法及螺纹配合等级说明
  20. 云计算python Spring cloud 微服务

热门文章

  1. 0507Python基础-set-深浅copy
  2. spring data 接口之 JpaRepository,JpaSpecificationExecutor
  3. [Google Guava]学习--新集合类型BiMap
  4. Hibernate 查询缓存
  5. Gitlab的管理使用手册
  6. python类库31[命令行解析]
  7. asp.net ashx + JQuery Ajax + XML
  8. java简单增删改查_无框架JavaWeb简单增删改查,纯 jsp小练习
  9. 微服务架构实战篇(一):使用start.spring.io 构建SpringBoot2.0项目
  10. 小程序如何避免多次点击,重复触发事件