ios - 使用 react-native-watch-connectivity 时出现 Watch App 无法访问错误
问题描述
我正在用我的 IOS 项目构建一个依赖手表应用程序,它是用 react native 编码的。我想发送消息以将手表应用程序中的数据与 IOS 应用程序同步,我使用了 react-native-watch-connectivity 并遵循以下链接中提到的完全相同的步骤,
http://mtford.co.uk/react-native-watch-connectivity/docs/installation
我在 react native 中的代码如下所示,
import React, { Component } from 'react'
import { Text, View , TouchableOpacity} from 'react-native'
import { sendMessage,sendMessageData, getReachability , getIsPaired, getIsWatchAppInstalled, transferUserInfo} from "react-native-watch-connectivity";
export default class Sample extends Component {
render() {
return (
<View>
<TouchableOpacity style = {{marginTop: 100, marginLeft: 40}}
onPress = {async() => {
const reachable = await getReachability()
console.log(reachable ? "Watch app is reachable" : "Watch app is not reachable")
const isPaired = await getIsPaired();
console.log(
isPaired ?
"phone is paired with a watch" :
"phone is NOT paired with a watch"
)
const isInstalled = await getIsWatchAppInstalled();
console.log(
isInstalled ?
"watch app is installed" :
"watch app is not installed"
)
}}
>
<Text> textInComponent </Text>
</TouchableOpacity>
</View>
)
}
}
但是当我看到我的日志时,我得到的是,
LOG Watch app is not reachable
LOG phone is paired with a watch
LOG watch app is installed
我不确定为什么无法访问手表应用程序。只是为了测试,我尝试卸载我的手表应用程序并尝试从我的手机发送消息,并且正如预期的那样,3 日志显示为未安装手表应用程序。
请注意,我在模拟器和真实设备上都对此进行了测试,结果是相同的。我的手表应用程序目标版本是 7.0 及更高版本,手表应用程序中的 UI 是使用 Swift UI 开发的。
请任何可以详细说明和支持此问题的人将不胜感激!
解决方案
推荐阅读
- google-sheets-api - Sheets API V4 电子表格视图属性
- reporting-services - SSRS 箭头指示器开始和结束
- javafx - 在 TableView 列 JavaFX 中使用 ObservableList 的索引
- html - 网站不能在移动设备上垂直滚动
- java - 数组过滤算法
- visual-studio-2017 - Net Standard - Nuget 包将包发布为命令行中的“添加”关键字
- python - 在 keras 中创建自定义激活函数
- python - 给定一个字符串列表,我如何将它们分成字符串?
- mongodb - mongoDB distect 问题
- python - 快速循环像素numpy