export default { onLaunch: function(options) { console.log('欢迎使用Whotalk即时通讯系统'); console.log('Whotalk官网:https://www.whotalk.com.cn/'); if(options.query){ let fromuid = options.query.fromuid; if(typeof(options.query.debug)!='undefined') core.debug = options.query.debug=='yes' ? true : false; if(options.query.q){ fromuid = core.urlParams(decodeURIComponent(options.query.q), 'fromuid'); } if(fromuid){ core.agentid = parseInt(options.query.fromuid); } } let userstate = typeof(options.query.state)=='undefined' ? '' : options.query.state; core.init(userstate); uni.getSystemInfo({ success: function(e) { let custom, CustomBar; // #ifndef MP Vue.prototype.StatusBar = e.statusBarHeight; if (e.osName == 'android') { CustomBar = e.statusBarHeight + 50; } else { CustomBar = e.statusBarHeight + 45; core.device = 'ios'; }; // #endif // #ifdef MP-WEIXIN custom = wx.getMenuButtonBoundingClientRect(); CustomBar = custom.bottom + custom.top - e.statusBarHeight; // #endif // #ifdef MP-TOUTIAO custom = tt.getMenuButtonBoundingClientRect(); CustomBar = custom.bottom + custom.top - e.statusBarHeight; // #endif // #ifdef MP-TOUTIAO || MP-WEIXIN Vue.prototype.StatusBar = e.statusBarHeight; Vue.prototype.Custom = custom; // #endif // #ifdef MP-ALIPAY CustomBar = e.statusBarHeight + e.titleBarHeight; // #endif Vue.prototype.CustomBar = e.CustomBar = CustomBar; core.Client = e; } }) // #ifdef APP-PLUS if(typeof(plus.push)!='undefined'){ const _handlePush = function(message) { // TODO let payload = message.payload; if(core.isJsonString(payload)){ payload = JSON.parse(payload); } if(typeof(payload.pagePath)!='undefined'){ let ws = plus.webview.currentWebview(); let weburl = ws.getURL(); let redt = weburl.indexOf('dialog/index')>-1 ?
时间: 2025-03-29 21:18:03 浏览: 45
### 处理推送消息并初始化应用
在 Vue 和 Uni-app 中,`plus.push` 是用于处理推送消息的核心模块之一。以下是详细的实现方法:
#### 1. 使用 `plus.push` 处理推送消息
为了监听和响应推送消息,在应用程序启动时可以通过注册事件来捕获推送通知的内容。
```javascript
// 注册推送消息接收事件
plus.push.addEventListener("receive", function (msg) {
console.log("收到一条新消息:" + msg.content);
}, false);
// 当用户点击通知时触发此事件
plus.push.addEventListener("click", function (msg) {
alert("您点击了一条通知:" + msg.content);
}, false);
```
上述代码实现了两个功能:当设备接收到推送消息时会打印日志[^1];当用户点击通知时弹出提示框显示具体内容[^2]。
#### 2. 初始化应用并设置状态栏高度
由于不同平台的状态栏高度可能有所不同,因此需要动态调整以适配各端环境。
对于 Android 平台:
- 可以直接调用 API 获取当前屏幕尺寸及状态栏大小;
```javascript
if (uni.getSystemInfoSync().platform === 'android') {
let statusBarHeight = plus.navigator.getStatusBarHeight();
document.getElementById('status-bar').style.height = `${statusBarHeight}px`;
}
```
针对 iOS 设备,则需特别注意是否存在刘海屏设计影响布局效果的情况:
```javascript
else if (uni.getSystemInfoSync().platform === 'ios') {
const systemInfo = uni.getSystemInfoSync();
// 假设顶部安全区域距离等于状态栏高
var safeAreaInsetsTop = parseFloat(systemInfo.safeAreaInsets.top || 0);
document.getElementById('safe-area-top').style.paddingTop = `${safeAreaInsetsTop}px`;
}
```
以上脚本片段分别演示了如何依据操作系统差异设定合适的 UI 参数值[^3]。
#### 注意事项
开发期间务必确认已正确集成第三方服务(如极光推送 JPush 或小米推送 MiPush),因为这些 SDK 提供更全面的功能支持,比如离线消息缓存机制等特性[^4]。
---
###
阅读全文
相关推荐





