react-native - HMS 地理围栏未触发事件
问题描述
我在尝试使用HMS Geofencing
( React Native
) 时遇到问题。我正在设置服务,如下所示:
- 将地理围栏添加到地理围栏列表
const geofence = {
latitude: latitude,
longitude: longitude,
radius: radius,
uniqueId: identifier,
conversions:
HMSLocation.Geofence.Native.GeofenceConstants.ENTER_GEOFENCE_CONVERSION |
HMSLocation.Geofence.Native.GeofenceConstants.EXIT_GEOFENCE_CONVERSION,
}
geofenceList.push(geofence)
- 如文档中所述启动地理围栏
async startGeofencingTask(): Promise<void> {
logger.info('Starting geofencing task')
try {
const regions = await this.loadGeofencedPositions()
// getting geofenceList as shown before from an array of regions
const geofenceList = this.convertToHMSGeofenceList(regions)
const conversionType =
HMSLocation.Geofence.Native.GeofenceRequestConstants.ENTER_INIT_CONVERSION |
HMSLocation.Geofence.Native.GeofenceRequestConstants.EXIT_INIT_CONVERSION
const coordinateType = HMSLocation.Geofence.Native.GeofenceRequestConstants.COORDINATE_TYPE_WGS_84
HMSLocation.Geofence.Native.createGeofenceList(GEOFENCING_TASK_ID, geofenceList, conversionType, coordinateType)
HMSLocation.Geofence.Events.registerGeofenceHeadlessTask(huaweiGeofencingTask)
HMSLocation.Geofence.Events.addGeofenceEventListener(huaweiGeofencingTask)
} catch (error) {
logger.warn(`Unable to start geofencing task`, error)
}
}
使用此设置,我只收到第一个触发器,但从那时起,无论应用程序处于前台还是后台,我都没有收到任何更新。关于为什么我只获得初始更新的任何线索?
编辑: 使用权限设置为文档中的:
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
解决方案
确保您已将位置权限授予应用程序,并且您已在 Android Manifest 中注册了广播接收器。
<receiver
android:name=".geofence.GeoFenceBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.huawei.hmssample.geofence.GeoFenceBroadcastReceiver.ACTION_PROCESS_LOCATION" />
</intent-filter>
</receiver>
推荐阅读
- spring - 401 在 authenticationManager.authenticate() 上未经授权(Spring Security)
- python - 试图制作一个 python 递归函数来检查一个字符是否在给定的字符串中但是我没有
- node.js - Cassandra / Scylla 编组错误:read_simple_bytes - 字节数不足(请求 841888305,得到 10)
- sql - T-SQL如何返回Total items的X item
- sql - 有没有办法在 SQL 中计算计数别名的总和?
- c - 在 Visual Studio 中使用 printf 时不显示文本
- arduino - 从传感器到 heltec wifi kit 8 的串行通信?
- java - Gson 为什么我的反序列化不起作用?
- audio - 截取其他程序的声音
- python - 案例的笛卡尔积的代码设计