繁体   English   中英

Flutter permission_handler IOS 位置

[英]Flutter permission_handler IOS location

我想知道用户是在使用时选择还是始终选择(位置权限)。

我在 IOS 13 模拟器上使用此代码

static Future<PermissionStatus> checkPermissions() async {
    PermissionStatus permission = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.locationAlways);
    return permission;
  }

这将返回“GRANTED”,我希望它返回“always”或“when_in_use”。

这可能吗?

提前致谢!

我相信您现在已经明白了这一点,但问题是您要求的是locationAlways的状态——对于该特定权限将被授予或拒绝。 要了解locationWhenInUse的状态,您必须直接询问。

自从提出这个问题以来, permission_handler发生了变化,但对于您的情况,您可以像这样使用它:

  Future<String> checkPermissions() async {
    PermissionStatus whenInUse = await Permission.locationWhenInUse.status;
    if (whenInUse == PermissionStatus.granted) return "when_in_use";

    PermissionStatus always = await Permission.locationAlways.status;
    if (always == PermissionStatus.granted) return "always";

最后一个旁注——因为我偶然发现了这个问题,寻找为什么 iOS 在请求许可时遇到问题。 在 iOS 上请求位置权限时,请务必特别请求locationWhenInUselocationAlways Android 允许您请求一般位置权限( Permission.location.request()而不是Permission.locationAlways.request() ),但我发现前者在 iOS 上失败了,恕不另行通知。
希望这有助于在某个地方节省一些时间。

暂无
暂无

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

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