我们正在使用 React Native 进行智能手表支持的研发。 研发范围就像通过手机连接到智能手表,然后当来自手机插座的事件时触发/振动手表。因此,那时我们将从手机向智能手表发送一些特定的消息来启动振动。
在搜索相同内容时,我们遇到了这个SO问题,其中表示RN不支持智能手表(记住该帖子是2016年的)
在同一篇文章中提到了 ReactNative Vanilla,我完全不明白
然后我遇到了这个 GitHub 但这涉及本机端编码。
如果有人能对此有任何见解,那将会很有帮助 预先感谢
尝试搜索相同内容,但找不到任何有用的东西
yarn add react-native-wear-connectivity
npx react-native@latest init YourMobileAppName
<!-- this file is located at android/app/src/main/AndroidManifest.xml -->
<uses-feature android:name="android.hardware.type.watch" />
yarn start --port=8082
yarn android
构建项目,打开 react 本机开发菜单并将捆绑包位置更改为 your-ip:8082
(例如 192.168.18.2:8082
)。您现在可以使用
yarn android
构建应用程序。 JS 快速刷新和其他 Metro 功能工作没有问题。
import { sendMessage } from 'react-native-wear-connectivity';
sendMessage({ text: 'Hello watch!' });
import { watchEvents } from 'react-native-wear-connectivity';
const unsubscribe = watchEvents.on('message', (message) => {
console.log('received message from watch', message);
});