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



我使用的是Geolocator插件版本6.1.7。

当我尝试请求当前位置时,我的应用程序会毫无例外地突然关闭。调试控制台显示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/>

我去掉了这条线,崩溃的问题就消失了。

希望这能帮助到其他有类似经历的人。

我也遇到过类似的问题,但我能够通过向info.plist文件添加后台模式权限来解决它,就像这样。

<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>

最新更新