Expo Location geofencing not working on standalone devices IOS

守給你的承諾、 提交于 2020-12-08 00:51:34

问题


I am unable to run Location.startGeofencingAsync on standalone devices but it is running perfectly fine on simulator. This function gets triggered on Simulator and I can see the logs within this function but as soon as I switch to standalone device, It does not work.

Here is the error I am constantly getting when running on the standalone device

Error: Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient) || _CFMZEnabled()

Any help would be much appreciated.

Here is the code that I wrote:

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"
        ]
      }
    }
  }
}

App.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"
  }
});

来源:https://stackoverflow.com/questions/60199774/expo-location-geofencing-not-working-on-standalone-devices-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!