【问题标题】:Xamarin Forms location services work on iOSimulator but not on Testflight buildXamarin Forms 位置服务适用于 iOS 模拟器,但不适用于 Testflight 构建
【发布时间】:2018-11-11 21:43:40
【问题描述】:

我正在开发一个 Xamarin Forms 应用程序,该应用程序使用 PermissionsPlugin 向用户询问位置服务权限。我在 Windows 中使用 Visual Studio 2017 并使用虚拟机作为我的 MAC 构建主机(macOS High Sierra 10.13.4)。

我的问题是应用程序在部署到 iOS 模拟器时按预期工作。它提示用户允许或拒绝使用位置服务。在模拟器中,该应用程序甚至列在“设置”>“隐私”>“位置服务”下。但是在将构建的 IPA 文件交付给 Apple 并通过 Testflight 对其进行测试后,该应用程序不会提示任何内容,只会无限期地加载。该应用程序也未在“设置”>“隐私”>“位置服务”中列出。

这是应用程序请求权限的代码:

    async Task<bool> AskPermission()
    {
        var hasPermission = false;

        try
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);

            if (status != PermissionStatus.Granted)
            {

                if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                {
                    await App.Current.MainPage.DisplayAlert("Need location", "Allow app to access location?", "OK", "Cancel");
                }

                var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);

                if (results.ContainsKey(Permission.Location))
                {
                    status = results[Permission.Location];
                }
            }

            if (status == PermissionStatus.Granted)
            {
                hasPermission = true;
            }
            else if (status != PermissionStatus.Unknown)
            {
                await App.Current.MainPage.DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
            }
        }
        catch (Exception ex)
        {

        }

        return hasPermission;
    }

这是单击按钮时调用的方法之一。然后会出现一个活动指示器,因为它绑定到一个在所有方法启动/完成时切换的布尔值。

这几乎是 James Montemagno 插件中的示例代码。我怀疑该应用程序卡在await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location) 上。

我还在App的iOS项目中的Info.plist中添加了必要的补充:

<key>NSLocationWhenInUseUsageDescription</key>
<string>prompt message</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>prompt message</string>

我还测试了使用NSLocationAlwaysUsageDescription 而不是NSLocationWhenInUseUsageDescription 的变体,但得到了相似的结果...

我在 iOSimulator(iPhone 5、6、7,都在 11.3 中,都可以工作)中对此进行了测试,并在 Testflight 中使用 iPhone 7 和 iPad 进行了测试,两者都在 11.3 中;不幸的是,这两种情况都没有提示权限请求对话框。

作为参考,这在 Android 中在 Play 商店的调试和测试中都可以正常工作。

【问题讨论】:

    标签: ios xamarin.forms permissions location testflight


    【解决方案1】:

    我得到了修复;只需包含所有 3 个NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription...

    我的印象是我只能添加NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription 之一。我一定是在某个地方读到了一个过时的答案,给我留下了错误的印象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多