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

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

问题描述

我看过这个问答

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

谢谢!

解决方案

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

如何检查是否授予访问权限

来自支持团队:

<块引用>

众所周知,没有这样的 API 来检查用户权限.

来自支持团队:

<块引用>

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

  • 默认情况下,连接将失败并显示 NSURLErrorNotConnectedToInternet.
  • 如果您在会话配置上设置 waitsForConnectivity,请求将等待事情改善.在这种情况下,您将收到-URLSession:taskIsWaitingForConnectivity: 委托回调告诉你这件事.如果用户改变主意并启用本地网络访问,然后连接将通过.

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


如何触发这个弹窗

来自支持团队:

<块引用>

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

我见过其他开发人员遇到这种情况并且没有直接API触发本地网络权限警报相当恼人的.我鼓励您提交关于此的错误.

我一直在与本地网络隐私团队讨论这个问题以及我们当前针对您的情况的应用程序的建议 - 即,应用程序想要接收广播但不发送任何本地网络流量 -如下:

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

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

更新

对于 iOS 14.2 - 收到入站流量提示已修复.因此,您不需要下面的示例来模拟流量以触发提示.


这里是虚拟出站流量模拟的类:示例

<块引用>

该流量永远不会离开 iOS 设备,因此,即使界面处于休眠状态,不会唤醒它.即使它真的醒了界面,它的成本微不足道,因为你没有这样做一遍又一遍,只需要一次就可以触发本地网络隐私提醒.

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".

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).

Thank you!

解决方案

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

How to check is access granted or not

From support team:

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

From support team:

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.

  • 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.


How to trigger this popup

From support team:

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.

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:

  • 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.

  • 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.

UPDATE

For iOS 14.2 - prompt is received for inbound traffic FIXED. Because of this you don't need below example for simulating traffic to triggering prompt.


Here is class for dummy outgoing traffic simulation: example

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天全站免登陆