繁体   English   中英

如何在 ios 上启动应用程序时请求权限?

[英]How on ios when launching an application, request permission?

在此处输入图片说明 启动应用程序时,如何在 Ios 上请求权限? 不出现警报窗口。

对 Info.plist 文件进行了以下设置:

<key>UIBackgroundModes</key>
 <array>
    <string>location</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>Required for the application to work</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Required for the application to work</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Required for the application to work</string>

不出现警报窗口。

使用 Location 时,仅在 Info.plist 中添加 key-vaule 是不够的,还需要在应用运行时请求权限。

添加以下代码以进行尝试:

CLLocationManager locationManager = new CLLocationManager();

locationManager.RequestWhenInUseAuthorization();
//Requests permission to use location services while the app is in the foreground.

Or

locationManager.RequestAlwaysAuthorization();
//Requests permission to use location services whenever the app is running.

这是苹果文档xamarin 示例。

暂无
暂无

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

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