【问题标题】:UWP (C#) - Getting result of PermissionRequestUWP (C#) - 获取 PermissionRequest 的结果
【发布时间】:2023-04-09 17:34:01
【问题描述】:

如何检查用户是否允许需要使用用户位置的 WebView 的 PermissionRequest。用户单击“拒绝”后,未到达带有我的消息对话框的行。

private async void webView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
{
    if (args.PermissionRequest.PermissionType == WebViewPermissionType.Geolocation)
        args.PermissionRequest.Allow();
    else
        await new MessageDialog("Geolocation services must be allowed for this app. Please check your settings.").ShowAsync();
}

谢谢。

【问题讨论】:

    标签: c# geolocation win-universal-app


    【解决方案1】:

    您必须检查WebViewPermissionRequest.State 以确定该用户是否已授予权限。使用args.State

    这一行

    if (args.PermissionRequest.PermissionType == WebViewPermissionType.Geolocation)
    

    只检查请求权限的类型。与用户之前是否授予权限无关。

    【讨论】:

    • 那么向用户显示提示的事件是:args.PermissionRequest.Allow();?
    • if(args.State != WebViewPermissionState.Allow) args.PermissionRequest.Allow();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-14
    相关资源
    最近更新 更多