uni app无法收到消息
- 发布:2021-08-03 17:54
- 更新:2024-01-19 16:27
- 阅读:1424
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: windows10
HBuilderX类型: 正式
HBuilderX版本号: 3.1.22
手机系统: Android
手机系统版本号: Android 10
手机厂商: 模拟器
手机机型: Android Emulator 10.1_WXGA_Tablet_API_29
页面类型: vue
打包方式: 离线
项目创建方式: HBuilderX
操作步骤:
预期结果:
uni app可以收到消息
uni app可以收到消息
实际结果:
uni app无法收到消息
uni app无法收到消息
bug描述:
安卓中使用发送:
Map<String,Object> params=new HashMap<>();
params.put("title", remoteMessage.getNotification().getTitle());
params.put("body", remoteMessage.getNotification().getBody());
WXSDKInstance wxsdkInstance = new WXSDKInstance();
wxsdkInstance.fireGlobalEventCallback("fcmNotify", params);
uni中获取:
plus.globalEvent.addEventListener('fcmNotify', function(e){
uni.showModal({
title:'fcm notify',
content:"fcmNotify收到:"+JSON.stringify(e)
});
});
List<WXSDKInstance> instances = WXSDKManager.getInstance().getWXRenderManager().getAllInstances();
for (WXSDKInstance instance : instances) {
instance.fireGlobalEventCallback(eventName, result);
}
WXSDKInstance 是页面的实例。代码new出来的实例是不会生效的。你需要在UniModule或者UniComponent中获取实例。还需要注意的是fireGlobalEvent是一对一页面的不是任意Instance实例执行fireGlobalEvent都能监听到的
f***@sina.com
还是这个最靠谱
2022-09-29 15:02