【问题标题】:Flutter app crashes when requesting location on iOS在 iOS 上请求位置时 Flutter 应用程序崩溃
【发布时间】:2021-03-05 19:26:48
【问题描述】:

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

当我尝试请求当前位置时,我的应用突然关闭,没有任何异常。 调试控制台说Lost connection to device. Exited (sigterm)

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

代码如下:

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>

我有什么遗漏吗?

编辑:

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

【问题讨论】:

  • 您是否确认您的应用有权在设备/模拟器上使用位置信息?
  • 是的,我有。我有完全的许可。我还进入了 iphone 的设置以确保该应用程序具有最高级别的权限。我忘了在问题中添加这个。现在将添加。
  • 我在这里看不到任何会导致此问题的内容。你确定是因为getCurrentPosition 电话吗?没有这条线,你能在 iOS 上运行应用程序吗?
  • 是的,我可以在没有线路的情况下运行它。出于测试目的,我使用模型位置运行应用程序://position = await Geolocator.getCurrentPosition();位置=位置(纬度:33.8600217,经度:-78.039695);以上工作正常。
  • 您共享的代码和描述符没有任何问题。仔细检查 Info.plist 是否有任何拼写错误或缩进错误。运行flutter clean。问题肯定是由于在某个地方无法访问 iOS 上的 GPS。你只需要追踪到哪里。

标签: ios flutter dart geolocation flutter-dependencies


【解决方案1】:

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

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

&lt;key&gt;EnableBackgroundLocationUpdates&lt;/key&gt; &lt;true/&gt;

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

希望这对遇到类似情况的其他人有所帮助。

【讨论】:

  • 对我不起作用(Flutter 2)。 info.plist 中唯一的位置就是:NSLocationWhenInUseUsageDescription$(PRODUCT_NAME) location use。那是因为苹果想要它。
猜你喜欢
  • 1970-01-01
  • 2018-01-26
  • 1970-01-01
  • 1970-01-01
  • 2014-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多