a***@yuminstall.top
a***@yuminstall.top
  • 发布:2021-08-03 17:54
  • 更新:2024-01-19 16:27
  • 阅读:1030

globalEvent 事件无法使用

分类:uni-app

产品分类: 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无法收到消息

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)  
				  });  
			});
2021-08-03 17:54 负责人:无 分享
已邀请:
aak12345

aak12345

List<WXSDKInstance> instances = WXSDKManager.getInstance().getWXRenderManager().getAllInstances();
for (WXSDKInstance instance : instances) {
instance.fireGlobalEventCallback(eventName, result);
}

DCloud_Android_ST

DCloud_Android_ST

WXSDKInstance 是页面的实例。代码new出来的实例是不会生效的。你需要在UniModule或者UniComponent中获取实例。还需要注意的是fireGlobalEvent是一对一页面的不是任意Instance实例执行fireGlobalEvent都能监听到的

阿依牛牛

阿依牛牛

我现在遇到问题是第一次安装的时候安卓代码已经触发回调了,但是在 vue 获取不到,杀死 app 后再次打开就可以获取到了

  • aak12345

    List instances = WXSDKManager.getInstance().getWXRenderManager().getAllInstances();

    for (WXSDKInstance instance : instances) {

    instance.fireGlobalEventCallback(eventName, result);

    } 正常这个是可以的,因为这个是发送到所有页面的


    2024-01-19 16:30

  • 阿依牛牛

    搞定了,安卓端发送前循环获取WXSDKInstance实例,获取到后不要立即发送,要等几秒后再发送


    2024-01-19 16:34

要回复问题请先登录注册