是什么触发了 iOS 14 上的 "would like to find and connect to devices on your local network" 权限通知?

What triggers the "would like to find and connect to devices on your local network" permission notification on iOS 14?

在 iOS 14 上,除了 Bonjour 之外,哪些实际方法调用会触发“想要查找并连接到本地网络上的设备”权限通知?

这是来自 WWDC session 关于此新权限的屏幕截图。这只是作为一个概述有点帮助。我更感兴趣的是弄清楚是什么所有方法调用触发了这个。

简而言之,Bonjour。它的使用不再是“透明的”。有关详细信息,请参阅 https://developer.apple.com/videos/play/wwdc2020/10110/

If your app interacts with devices using Bonjour or other local networking protocols, you must add support for local network privacy permissions in iOS 14.

即使是现有的应用程序也受此规则约束;第一次尝试使用 Bonjour 会触发授权警报。

关于 iOS 14:权限请求:想要查找并连接到您本地网络上的设备,并且在对我的物理设备进行多次部署之后,我已经弄清楚是什么原因导致了我的情况。

我有一个 Xamarin.Forms 应用

  1. 在我开发时调用 localhost:xxxx 进行一些本地日志记录
  2. 我使用一个名为 LiveSharp 的产品,它可以为 XAML 和 C# 代码更改进行本地热重载。

所以 Livesharp 实际上也与我本地主机上的服务器通信。 在我的物理设备上禁用这两个和全新安装后,权限请求已经消失 .. Yay

注意:我必须从我的项目中完全删除 LiveSharp nuget 包。 我还尝试 re-enable 我的本地主机日志记录,但由于某种原因,权限请求没有出现。:headscratch

因此:删除您应用中发生的任何本地主机通信。或者至少在它周围放置一个 if 语句,允许它在 appsettings

中设置为 true

我的一个应用程序在我们的互联网多人游戏模式下意外触发了这个提示。我们将 RakNet 用于我们的网络(这是一个使用 BSD 套接字到 send/receive UDP 的 C++ 库)并且我能够将问题跟踪到 RNS2_Berkley::BindShared 函数 here.

创建 UDP 套接字后,RakNet 测试 health/validity 套接字,让它向自己发送一个小测试包。 iOS 14 将此 send-to-self 行为标记为本地网络上的通信。我不确定这种 send-to-self 行为是套接字编程中的常见模式,还是 RakNet 的特殊怪癖。令人沮丧的是,OS 提示直到后来真正使用套接字时才真正出现,这使得问题很难跟踪。

我认为这是来自 OS 的 false-positive 并与 Apple (FB8802121) 一起提出的。不过我不会屏住呼吸,所以我刚刚禁用了 iOS 的 RakNet 行为,希望它不是太重要。

编辑:为了更直接地回答原始问题:sendto 是一个可以触发此提示的方法调用。

我也有一个 Xamarin 应用程序,我使用了 LiveXaml 包。删除它后,消息消失了。

如果您在调试配置中使用 react native,那么您将包括所有负责与您的开发机器通信的代码,因此您可以忽略此消息。

不过,最好检查一下您是否没有其他需要访问权限的库。为此,只需构建一个发布版本并查看消息是否仍然存在。

我因为这个提醒被苹果应用审查拒绝了。我正在使用 GCDWebServer,它在我的应用程序中创建了一个嵌入式 http 服务器。

我想我应该在 info.plist 中提供一条消息来告诉用户我的应用程序想要做什么。在我没有在其中设置文本字符串之前。

如果这将通过应用审核,我想更新。

<key>NSLocalNetworkUsageDescription</key>
<string>xxx uses the local network to connect with devices around you.</string>

Apple(开发论坛上的爱斯基摩人)发布了一个常见问题解答,提供了有关此警报的更多详细信息: https://developer.apple.com/forums/thread/663858

特别是,FAQ-2 提供了有关触发此警报的更多信息: https://developer.apple.com/forums/thread/663874

What operations require local network access?

The general rule is that outgoing traffic to a local network address requires that the user grant your app local network access. Common scenarios include:

  • Making an outgoing TCP connection — yes
  • Listening for and accepting incoming TCP connections — no
  • Sending a UDP unicast — yes
  • Sending a UDP multicast — yes
  • Sending a UDP broadcast — yes
  • Receiving an incoming UDP unicast — no
  • Receiving an incoming UDP multicast — yes
  • Receiving an incoming UDP broadcast — yes

These TCP and UDP checks are done at the lowest levels of the system and thus apply to all networking APIs. This includes Network framework, BSD Sockets, NSStream, NSURLSession and WKWebView, and any other protocols that you layer on top of those.

IMPORTANT Receiving an incoming UDP multicast or broadcast does not currently require local network access but, because we hope to change that in a future update, our advice right now is that you write your code as if did (r. 69792887, 70017649).

Resolving link-local DNS names (those ending with local, per RFC 6762) requires local network access. Again, this check applies to a wide variety of APIs including <dns_sd.h>, <net_db.h>, Network framework, NSStream, and NSURLSession.

Finally, all Bonjour operations require local network access:

  • Registering a service with Bonjour — yes
  • Browsing for Bonjour services — yes
  • Resolving a Bonjour service — yes

Again, these checks apply to all APIs that use Bonjour, including <dns_sd.h>, Network framework, NSNetService, and Multipeer Connectivity.

Note You must declare the Bonjour service types you use in your Info.plist. See How do I map my Multipeer Connectivity service type to an entry in the Bonjour services property? for details.

Bonjour-based services where you don’t see any details of the network do not require local network access. These include:

  • AirPlay — no
  • Printing via UIKit — no