如何解决 flutter 中的 'allowsBackgroundLocationUpdates' 错误

How can I resolve 'allowsBackgroundLocationUpdates' error in flutter

当我 运行 我的 flutter 应用程序时,我收到了一些与位置设置相关的错误。

错误 1:

/Users/mustafazaki/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/location-3.2.4/ios/Classes/LocationPlugin.m:84:43: note: enclose 'allowsBackgroundLocationUpdates' in an @available check to silence this warning result(self.clLocationManager.allowsBackgroundLocationUpdates ? @1 : @0);

错误2:

/Users/mustafazaki/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/location-3.2.4/ios/Classes/LocationPlugin.m:91:36: warning: 'setAllowsBackgroundLocationUpdates:' is only available on iOS 9.0 or newer [-Wunguarded-availability] self.clLocationManager.allowsBackgroundLocationUpdates = enable;

错误 3:

/Users/mustafazaki/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/location-3.2.4/ios/Classes/LocationPlugin.m:92:36: note: enclose 'setShowsBackgroundLocationIndicator:' in an @available check to silence this warning self.clLocationManager.showsBackgroundLocationIndicator = enable;

尝试将此代码添加到您的 info.plist ios->Runner->Info.plist <dict> 标签内。

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Location permission</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Location permission</string>
<key>NSLocationUsageDescription</key>
<string>Location permission</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location permission</string>

停止您的应用程序,然后在终端中 运行 :

  1. 颤抖干净
  2. flutter pub get
  3. 颤动运行