【发布时间】:2020-04-02 01:09:55
【问题描述】:
我正在尝试使用广播 iBeacon 的 React Native 创建一个简单的应用程序。我找到了一个可能的第三方模块react-native-ibeacon-simulator,但即使是简单的测试也失败了。我知道这已经有一段时间没有更新了,但是我找不到更好的解决方案...
我将index.ios.js 文件保存为 iBeacon.js
import React, { Component } from 'react'
import { Text, View } from 'react-native'
import ibeacon from './ibeacon'
export default class App extends Component {
componentWillMount() {
const uuid = '04bc1d42-98be-4031-a4a9-50c76cb3e1b9'
const identifier = 'com.myapp'
ibeacon.startAdvertisingBeaconWithString(uuid, identifier, 0, 0)
}
render() {
return (<View><Text>iBeacon</Text></View>)
}
}
但是我在终端(以及运行 iOS13 的已连接 iPhone 6S 的屏幕上)出现以下错误:
Warning: %s: Error boundaries should implement getDerivedStateFromError(). In that method, return a state update to display an error message or fallback UI., RootErrorBoundary
- node_modules/expo/build/environment/muteWarnings.fx.js:27:24 in error
- ... 28 more stack frames from framework internals
TypeError: null is not an object (evaluating 'NativeBeaconBroadcast.startSharedAdvertisingBeaconWithString')
* ibeacon.js:19:26 in startAdvertisingBeaconWithString
* App.js:12:43 in componentWillMount
- node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:7430:4 in callComponentWillMount
- node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:7576:27 in mountClassInstance
- ... 19 more stack frames from framework internals
我试过调试,但不知道为什么会这样……
【问题讨论】:
-
我也遇到了同样的问题...运气好吗?
标签: ios node.js react-native ibeacon