Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新架构NativeEventEmitter问题,求解决 #941

Closed
chentogit opened this issue Feb 19, 2025 · 2 comments
Closed

新架构NativeEventEmitter问题,求解决 #941

chentogit opened this issue Feb 19, 2025 · 2 comments

Comments

@chentogit
Copy link

chentogit commented Feb 19, 2025

问题的具体描述

0.76版本的新架构无法使用NativeEventEmitter事件类,从原生代码发送事件到js了吗?一直提示Sending QAVoiceRecognizerMsgEvent with no listeners registered.

代码如下:

import {TurboModule, TurboModuleRegistry} from "react-native";

export interface Spec extends TurboModule {
  initRecognize(): void;
  startRecognizeWithRecorder(type?: string): void;
  stopRecognizeWithRecorder(): void;
  // addListener(eventName?: string): void;
  // removeListeners(eventName?: number): void;
}

export default TurboModuleRegistry.getEnforcing<Spec>("QAVoiceRecognizer") as Spec;
const nativeEventListener = new NativeEventEmitter(TurboModuleRegistry.getEnforcing('QAVoiceRecognizer'));
    nativeEventListener.addListener('QAVoiceRecognizerMsgEvent', (eData={}) => {
      console.log(eData);
    });
    nativeEventListener.addListener('QAVoiceRecognizerVolumeEvent', (eData={}) => {
      console.log(eData);
    });

请描述完整的环境/版本信息

System:
  OS: macOS 14.4.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Memory: 29.41 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.9.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 10.1.0
    path: /usr/local/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/chen/.rvm/gems/ruby-3.2.3/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2411.12071903
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.1.1
    path: /usr/bin/javac
  Ruby:
    version: 3.2.3
    path: /Users/chen/.rvm/rubies/ruby-3.2.3/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.7
    wanted: 0.76.7
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

info React Native v0.77.1 is now available (your project is running on v0.76.7).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.77.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.76.7&to=0.77.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

预期结果

旧的项目可以正常在js端监听到原生发送过来的数据,升级新版本就这样了,难道只能用c++调用吗,可是c++忘的干干净净,而且就算用c++,数据源也是在oc获取的,怎么传递到c++啊?有知道的吗

@chentogit
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants