简体   繁体   English

如何在Xamarin iOS App中启用位置服务

[英]How to enable location services in Xamarin iOS App

I would like my simple to enable location services I have added the following in info.plist file 我想简单地启用位置服务我在info.plist文件中添加了以下内容

通用PList编辑器

I have enabled background modes and location (ios Manifest Editor view) 我启用了后台模式和位置​​(ios Manifest Editor视图) 在此输入图像描述

However when i install the app (from XCode on a connected IPad - IPA). 但是,当我安装应用程序时(从连接的IPad上的XCode - IPA)。 The app does popup a notification about allowing notifications however there is no message about enabling location services. 该应用程序会弹出有关允许通知的通知,但是没有关于启用位置服务的消息。

As per Ricardo's comment, I have added the required setting to my info.plist file. 根据里卡多的评论,我已将所需的设置添加到我的info.plist文件中。 My info.plist file looks like this now. 我的info.plist文件现在看起来像这样。

通用XML编辑器视图。

The only popup i get after building, reinstalling the ipa is allow notifications and no popup to allow location services. 我在构建,重新安装ipa后获得的唯一弹出窗口是允许通知,没有弹出窗口允许定位服务。 What am i missing? 我错过了什么?

It only ask when you start using location. 它只会询问您何时开始使用位置。 Alternatively you can force the app to prompt for user permission using Xamarin.Plugin.Permission package then check for permission and ask for it like this. 或者,您可以强制应用程序使用Xamarin.Plugin.Permission包提示用户权限,然后检查权限并请求这样做。

        var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location);
        if (status != PermissionStatus.Granted)
        {
            if(await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
            {
                await DisplayAlert("Need location", "Gunna need that location", "OK");
            }

            var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
            status = results[Permission.Location];
        }

NSLocationAlwaysUsageDescription is deprecated ( Source ), 不推荐使用NSLocationAlwaysUsageDescription源代码 ),

Use NSLocationWhenInUseUsageDescription instead. 请改用NSLocationWhenInUseUsageDescription Add this to your info.plist : 将其添加到您的info.plist

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your Message</string>

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

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