Я не могу запустить Location.startGeofencingAsyn c на автономных устройствах, но он отлично работает на симуляторе. Эта функция запускается на симуляторе, и я вижу журналы в этой функции, но как только я переключаюсь на автономное устройство, она не работает.
Вот ошибка, которую я постоянно получаю при работе на автономном устройстве
Error: Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient) || _CFMZEnabled()
Любая помощь будет принята с благодарностью.
Вот код, который я написал:
app. json
{
"expo": {
"name": "GeoFence",
"slug": "GeoFence",
"privacy": "public",
"sdkVersion": "36.0.0",
"platforms": [
"ios",
"android",
"web"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"infoPlist": {
"UIBackgroundModes": [
"location",
"fetch"
]
}
}
}
}
Приложение. js
import React from 'react';
import { StyleSheet, Text, View, Dimensions } from 'react-native';
import MapView, { Marker } from 'react-native-maps';
import * as TaskManager from 'expo-task-manager';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
export default class App extends React.Component {
state = {
markers: [
{
identifier: "101",
latitude: parseFloat("47.617192"),
longitude: parseFloat("-122.159015"),
radius: 300,
notifyOnEnter: true,
notifyOnExit: true,
}
],
currentLocation: undefined
}
componentDidMount(){
this._enableGeoFenceAsync()
}
_enableGeoFenceAsync = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if(status === 'granted') {
console.log("Permissions granted, fetching current location")
const loc = await Location.getCurrentPositionAsync({});
console.log("Current Location: "+loc)
this.setState({
currentLocation: loc
})
}
Location.startGeofencingAsync("LOCATION_GEOFENCE", this.state.markers)
}
render(){
return (
<React.Fragment>
<MapView
ref="map"
style={styles.mapStyle}
showsUserLocation={true}
followsUserLocation={true}
showsCompass={true}
showsScale={true}
showsMyLocationButton={true}
>
{this.state.markers.map(marker => (
<React.Fragment key={marker.identifier}>
<Marker
key={marker.identifier}
coordinate={{latitude: marker.latitude, longitude: marker.longitude}}
title={marker.identifier}
description={marker.identifier}
/>
</React.Fragment>
))}
{this.state.markers.map(marker => (
<React.Fragment key={marker.identifier}>
<MapView.Circle
key={marker.identifier}
center={{latitude: marker.latitude, longitude: marker.longitude}}
radius={marker.radius}
strokeColor={styles.circleStrokeColor.color}
fillColor={styles.circleFillColor.color}
strokeWidth={2}
/>
</React.Fragment>
))}
</MapView>
<Text>Current Location: {JSON.stringify(this.state.currentLocation)}</Text>
</React.Fragment>
);
}
}
TaskManager.defineTask("LOCATION_GEOFENCE", ({ data: { eventType, region }, error }) => {
if (error) {
// check `error.message` for more details.
console.log("ERROR: "+error)
return;
}
if (eventType === Location.GeofencingEventType.Enter) {
alert("enter in region!")
console.log("You've entered region:", region);
} else if (eventType === Location.GeofencingEventType.Exit) {
console.log("You've left region:", region);
}
});
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
marginTop: 2000
},
mapStyle: {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height - 100,
},
circleStrokeColor: {
color: "#f7364f",
},
circleFillColor: {
color: "#f7a1ac"
}
});