简体   繁体   English

无法在Windows 8上访问Geolocator

[英]Getting access denied for Geolocator on Windows 8

The following code is giving me an access denied exception: 以下代码给了我一个拒绝访问的异常:

Geolocator geolocator = new Geolocator();
Geoposition geopos = await geolocator.GetGeopositionAsync();

The error is as follows: 错误如下:

A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

I have given Location Capability and Declaration. 我已经给出了位置能力和声明。

Can anyone suggest why I may be getting this error? 谁能建议我为什么会收到此错误?

Did your app prompt you for consent when it started? 应用启动时是否提示您同意? If so, and you clicked Block, then you'll get this exception. 如果是这样,然后单击“阻止”,则会收到此异常。

If you didn't see the prompt, then permissions are cached--go to Settings > Permissions from your app to change it. 如果没有看到提示,则将缓存权限-从应用程序转到“设置”>“权限”进行更改。 Or uninstall the app and rerun, which will reset consent (as will changing your manifest and running again). 或卸载该应用并重新运行,这将重置同意(更改清单并再次运行)。

It's also possible that Location is turned off system wide. 也有可能在整个系统范围内关闭了位置信息。 Check PC Settings > Privacy > Location (on Windows 8.1; I forget where it is in Windows 8, but should be in there somewhere). 检查PC设置>隐私>位置(在Windows 8.1上;我忘记了它在Windows 8中的位置,但应该在该位置)。

Bottom line, though, is that because a user can deny consent on first access, and later turn it off via Settings > Permissions, you should always catch such exceptions with brokered APIs like this. 但是,最重要的是,因为用户可以拒绝首次访问的同意,然后再通过“设置”>“权限”将其关闭,所以您应该始终使用此类中介API捕获此类异常。 (That's the pattern: those APIs throw instead of returning a null in such cases.) (这就是模式:在这种情况下,这些API会抛出而不是返回null。)

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

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