使用https://github.com/MacKentoch/react-native-beacons-manager
在ios上很不错,但是在android上,当我开始排列信标之后,信标阵列显示出来,里面什么都没有(我旁边有6个信标,它们都显示在ios上)。
我要做的是:

componentDidMount() {

 // Start detecting all iBeacons in the nearby
Beacons.detectIBeacons();

Beacons.startRangingBeaconsInRegion('Estimotes', 'B9407F30-F5F8-466E-AFF9-25556B57FE6D').then((data)=>{

    console.log(data);

}).catch((reason) => {

    console.log(reason);


});


// Print a log of the detected iBeacons (1 per second)
DeviceEventEmitter.addListener('beaconsDidRange', (data) => {

    console.log(data);

});

}

在我的控制台中,我得到这个:
{beacons: Array(0), uuid: "b9407f30-f5f8-466e-aff9-25556b57fe6d", identifier: "Estimotes"}

我将estimotes的uuid保留为默认值,因此应该可以工作。使用三星Galaxy S8+进行测试。我在这里做了什么错事吗?在android上是否缺少其他权限?蓝牙和定位服务已打开。

最佳答案

好吧,我想出来了。较新版本的android需要额外的权限。在你的名单上,把这家伙扔进去:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

……如果您使用的是react native kontaktio(这比react native beacons manager imo更好),那么您还需要将其放入<application>部分的清单中:
<service android:name="com.kontakt.sdk.android.ble.service.ProximityService"/>

然后在app.js中,您需要请求类似于()的权限,确保
import PermissionsAndroid
from 'react-native'

以下内容:
componentDidMount() {

    try {
        const granted = PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
            {
                'title': 'Location Permission',
                'message': 'Activeev needs to access your location.'
            }
        )
        console.log('here', granted);
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            console.log("Location Permitted")
        } else {
            console.log("Location permission denied")
        }
    } catch (err) {
        console.warn(err)
    }
}

像个魔术师一样工作。希望这能帮助别人。

关于android - react-native-beacons-manager在Android上不显示任何信标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47358824/

10-09 18:25
查看更多