首页 > 解决方案 > 使用 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 开发的。

请任何可以详细说明和支持此问题的人将不胜感激!

标签: iosreact-nativeswiftuiwatchoswatchconnectivity

解决方案


推荐阅读