繁体   English   中英

在 iOS 上请求位置时 Flutter 应用程序崩溃

[英]Flutter app crashes when requesting location on iOS

我正在使用Geolocator插件版本 6.1.7。

当我尝试请求当前位置时,我的应用程序毫无例外地突然关闭。 调试控制台显示Lost connection to device. Exited (sigterm) Lost connection to device. Exited (sigterm)

这只发生在 iOS(物理设备和模拟器)上。 此功能在 android 模拟器和物理设备上运行良好。

这是代码:

Future<bool> getLocation(bool refresh) async {
position = await Geolocator.getCurrentPosition();

if (mapPosition == null || refresh) {
  mapPosition = position;
}

return true;

}

getCurrentPosition()函数处崩溃。

我在 Info.plist 文件中添加了所需的权限。

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your location is required to show you relevant meals in your area.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your location is required to show you relevant meals in your area.</string>

有什么我想念的吗?

编辑:

我已确保该应用已获得许可。 该位置的权限级别在设置中为“使用应用程序时”。 还确保我的位置在“设置”中打开。

在这里回答我自己的问题。

我浏览了 Info.plist 以查找任何异常,并注意到有一个用于后台位置更新的项目。

<key>EnableBackgroundLocationUpdates</key> <true/>

我摆脱了这条线,崩溃问题就消失了。

希望这可以帮助其他经历过类似事情的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM