使用React-Native创建智能手表支持应用程序

问题描述 投票:0回答:1

我们正在使用 React Native 进行智能手表支持的研发。 研发范围就像通过手机连接到智能手表,然后当来自手机插座的事件时触发/振动手表。因此,那时我们将从手机向智能手表发送一些特定的消息来启动振动。

在搜索相同内容时,我们遇到了这个SO问题,其中表示RN不支持智能手表(记住该帖子是2016年的)

在同一篇文章中提到了 ReactNative Vanilla,我完全不明白

  1. react-native vanila 是一个 npm 包还是像 React-native 这样的新域

然后我遇到了这个 GitHub 但这涉及本机端编码。

如果有人能对此有任何见解,那将会很有帮助 预先感谢

尝试搜索相同内容,但找不到任何有用的东西

react-native wear-os apple-watch wearables
1个回答
0
投票

反应原生磨损连接

  • 使用react-native创建Wear OS应用程序
  • 连接两个反应本机应用程序(Wear OS 和 Android 移动应用程序)
  • 这两个应用程序都是用react-native编写的

视频预览:https://github.com/fabOnReact/react-native-wear-connectivity/assets/24992535/415fab47-7d76-4c72-80b9-c0d19ec25a49

安装

yarn add react-native-wear-connectivity

如何使用react-native创建WearOS应用程序

  • 使用与您的移动应用程序相同的名称创建一个新的反应本机应用程序。 使用相同的名称很重要,因为两个应用程序需要共享相同的包名称(AndroidManifest、build.gradle、项目文件)和 applicationId (build.gradle)。
npx react-native@latest init YourMobileAppName
  • 将以下行添加到新项目 AndroidManifest(文件)中:
<!-- this file is located at android/app/src/main/AndroidManifest.xml -->
<uses-feature android:name="android.hardware.type.watch" />
  • 创建一个类型为 WearOS Large round 的新模拟器。
  • 将 Android 模拟器与 Wear OS 模拟器配对。请遵循此说明
  • 使用
    yarn start --port=8082
  • 在端口 8082 上启动 Metro 服务器
  • 使用
    yarn android
    构建项目,打开 react 本机开发菜单并将捆绑包位置更改为
    your-ip:8082
    (例如
    192.168.18.2:8082
    )。
  • 对 Android 手机模拟器重复相同的步骤并使用不同的端口(例如 8081)。
  • 重要提示:在发布到 Google Play 之前,请确保两个应用程序都使用相同的密钥进行签名(说明此处

您现在可以使用

yarn android
构建应用程序。 JS 快速刷新和其他 Metro 功能工作没有问题。

API文档

发送消息

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);
});
© www.soinside.com 2019 - 2024. All rights reserved.