gpt4 book ai didi

ios - 后台服务问题: App crush when using geolocator

转载 作者:行者123 更新时间:2023-12-02 02:14:23 26 4
gpt4 key购买 nike

我正在开发一个健身/健康 flutter 应用项目。

我的应用程序在 Android 上工作正常,但当我调用位置服务时,应用程序在 ios 中崩溃并立即停止工作。

我在 map View 页面内有一个按钮,可以开始计算步行的步数和时间。

我的按钮代码

  RaisedButton(
textColor: Colors.white,
color: checkRun == false
? Settings.mainColor()
: Colors.red,
child: Container(
padding: EdgeInsets.all(15),
child: checkRun == false
? Text(allTranslations.text("startNow"))
: Text(allTranslations.text("endNow"))),
onPressed: () async {
rightButtonPressed();
if (checkRun == false) {
getLocation();
} else if (checkRun == true) {
setState(() {
checkRun = false;
});
try {
FormData formdata = new FormData();
// get user token
SharedPreferences sharedPreferences =
await SharedPreferences.getInstance();
Map<String, dynamic> authUser = jsonDecode(
sharedPreferences
.getString("authUser"));
dio.options.headers = {
"Authorization":
"Bearer ${authUser['authToken']}",
};
formdata.add("startLongitude",
points.first.longitude);
formdata.add(
"endLongitude", points.last.longitude);
formdata.add(
"startLatitude", points.first.latitude);
formdata.add(
"endLatitude", points.last.latitude);
formdata.add("date", DateTime.now());

meter = distance.as(
lm.LengthUnit.Meter,
lm.LatLng(points.first.latitude,
points.first.longitude),
lm.LatLng(points.last.latitude,
points.last.longitude));
setState(() {});

print(meter);

formdata.add("distance", meter.toInt());
formdata.add("steps", _polylineIdCounter);
formdata.add("calories", (_polylineIdCounter*0.0512).toInt());

response = await dio.post(
"http://104.248.168.117/api/mapInformation",
data: formdata);
if (response.statusCode != 200 &&
response.statusCode != 201) {
return false;
} else {
print('success -->');
print('Response = ${response.data}');
return true;
}
} on DioError catch (e) {

return false;
}
}
// return true;
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0)))

getLoaction 代码:

 getLocation() {
setState(() {
checkRun = true;
});
print('CheckRun = > $checkRun');
// Fired whenever a location is recorded
bg.BackgroundGeolocation.onLocation((bg.Location location) {
print('[location] - $location');
print('<--------- start onLocation -----------> ');
print(location.coords.latitude);
print(location.coords.longitude);
print('<--------- End onLocation -----------> ');
if (checkRun == true) {
setState(() {
points.add(_createLatLng(
location.coords.latitude, location.coords.longitude));
print('Points=> $points');
_add();
});
} else if (checkRun == false) {
setState(() {
points.clear();
});
}
});

// Fired whenever the plugin changes motion-state (stationary->moving and vice-versa)
bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
print('[motionchange] - $location');
print('<--------- Locaiton onMotionChange -----------> ');
updatelat=location.coords.latitude;
updatelong=location.coords.longitude;
setState(() {

});
print(location.coords.latitude);
print(location.coords.longitude);
print('<--------- / Locaiton onMotionChange -----------> ');
});

// Fired whenever the state of location-services changes. Always fired at boot
bg.BackgroundGeolocation.onProviderChange((bg.ProviderChangeEvent event) {
});

////
// 2. Configure the plugin
//
bg.BackgroundGeolocation.ready(bg.Config(
desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
distanceFilter: 10.0,
stopOnTerminate: false,
startOnBoot: true,
debug: false,
logLevel: bg.Config.LOG_LEVEL_INFO,
reset: true))
.then((bg.State state) {
if (!state.enabled) {
////
// 3. Start the plugin.
//
print('[ready] success: $state');
bg.BackgroundGeolocation.start();
}
});}

我正在使用这些软件包:

  flutter_background_geolocation: ^1.2.4
geolocator: ^5.0.1

最佳答案

map View 在发布版本中很糟糕,因为您需要购买 flutter_background_geolocation 才能使其在发布版本中工作,因此当您在 Debug模式下构建应用程序时,它会很好地工作但它会压垮没有许可证的 Release模式。

关于ios - 后台服务问题: App crush when using geolocator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58311287/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com