iOS 14如何触发“本地网络"对话框并检查用户答案? [英] iOS 14 How to trigger Local Network dialog and check user answer?

查看:1159
本文介绍了iOS 14如何触发“本地网络"对话框并检查用户答案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过这个问题了,网络隐私权限检查,但没有答案.我还会在这里搜索对我有帮助的任何方法或类:网络,但是再没有运气了.

I've seen this Q/A What triggers, but it's not what I want. I also read this Network privacy permission check, but there is no answer. I also search for any methods or classes which can help me here: Network, but no luck again.

对于本地网络授权,有一个新对话框,用户可以在其中允许/不允许查找并连接到本地网络上的设备".

There is a new dialog for the Local Network authorization, where user can Allow/Don't Allow "to find and connect to devices on your local network".

但是我正在努力寻找任何API,以了解如何触发此弹出窗口以及如何检查是否授予访问权限(例如,在AVCapture中,我可以检查AVMediaType的授权状态).

But I'm struggling to find any API for how to trigger this popup and how to check is access granted or not(for example in AVCapture, I can check the authorization status for AVMediaType).

谢谢!

推荐答案

我确实打开了DTS请求,并与Apple支持团队进行了转换.这是我下面包含的一些重要部分.

I did open DTS request and had conversion with Apple support team. Here is some important parts which I included below.

来自支持团队:

要知道,没有这样的API可以检查用户权限.

For know, there is no such an API to check user permission.

来自支持团队:

如果用户拒绝,则连接失败.究竟是怎么失败的 取决于您使用的网络API以及如何使用该API.

If the user declines, the connection fails. Exactly how it fails depends on the network API you’re using and how you use that API.

  • 默认情况下,连接将失败,并显示NSURLErrorNotConnectedToInternet.
  • 如果在会话配置上设置waitsForConnectivity,则请求将等待情况改善.在这种情况下,您会收到 -URLSession:taskIsWaitingForConnectivity:委托回调 告诉你这个.如果用户改变主意并启用本地 网络访问,则连接将通过.
  • By default the connection will fail with NSURLErrorNotConnectedToInternet.
  • If you set waitsForConnectivity on the session configuration, the request will wait for things to improve. In that case you’ll receive the -URLSession:taskIsWaitingForConnectivity: delegate callback to tell you about this. If the user changes their mind and enables local network access, the connection will then go through.

不幸的是,没有直接的方法可以确定这种行为是否是 本地网络隐私限制或其他一些原因的结果 网络故障.

Unfortunately there’s no direct way to determine if this behaviour is the result of a local network privacy restriction or some other networking failure.


如何触发此弹出窗口

来自支持团队:

这里的问题是本地网络权限警报是 由传出流量触发,并且您不会产生任何传出 交通.解决此问题的唯一方法是生成一些虚拟的传出 流量以触发此警报.

the problem here is that the local network permission alert is triggered by outgoing traffic and you do not generate any outgoing traffic. The only way around this is to generate some dummy outgoing traffic in order to trigger this alert.

在这种情况下,我已经看到了其他开发人员,并且没有 直接API触发本地网络权限警报相当 恼人的.我鼓励您提交有关此问题的错误.

I’ve seen other developers in this situation and the absence of a direct API to trigger the local network permission alert is quite annoying. I encourage you to file a bug about this.

我一直在与本地网络隐私小组讨论此问题 以及我们当前针对您所处应用的建议-即 想接收广播但不发送任何本地网络流量- 如下:

I’ve been discussing this issue with the local network privacy team and our current advice for apps in your situation — that is, apps that want to receive broadcasts but don’t send any local network traffic — is as follows:

  • 系统应在处理此问题方面做得更好.我们正在将其作为错误 rdar://problem/67975514 进行跟踪.这不是固定的 当前的iOS 14.2b1版本,但您应该继续使用iOS进行测试 Beta种子释放时.

  • The system should do a better job of handling this. We’re tracking that as a bug rdar://problem/67975514. This isn’t fixed in the current iOS 14.2b1 release but you should continue to test with iOS beta seeds as they are released.

在此期间,您可以通过发送消息来强制显示本地网络隐私警报.我们特别建议您发送一个 大致等于您要尝试的消息的消息 接收,因此在您的情况下,这意味着发送IPv4 UDP广播.

In the meantime you can force the local network privacy alert to show by sending a message. We specifically recommend that you send a message that’s roughly equivalent to the message you’re trying to receive, so in your case that means sending an IPv4 UDP broadcast.


这是虚拟外向流量模拟的类: 示例


Here is class for dummy outgoing traffic simulation: example

该流量将永远不会离开iOS设备,因此,即使 界面处于睡眠状态,不会将其唤醒.即使它醒了 界面,代价是微不足道的,因为您没有这样做 一次又一次地触发本地网络 隐私警报.

That traffic will never leave the iOS device and thus, even if the interface is asleep, it won’t wake it up. And even if it did wake up the interface, the cost of that is trivial because you’re not doing it over and over again, just once in order to trigger the local network privacy alert.

这篇关于iOS 14如何触发“本地网络"对话框并检查用户答案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆