[SWIFT] Using a local network on iOS 14

Introduction

User permission is now required to communicate from iOS 14 to the local network. For example, if you use broadcast or multicast to automatically detect devices on your local network, the following alert dialog will be displayed to the user. In iOS14, I thought that I just asked the user for permission, but depending on the function, it is necessary to change the implementation or apply to Apple. See the URLs listed in Resources for more information. LocalNetworkPermission.png

Features that require permission for local network communication in iOS14

["Support local network privacy in your app (WWDC2020)"] In (https://developer.apple.com/videos/play/wwdc2020/10110/), if the user has permission to communicate with the local network, it is explained as follows.

Requires user permission

--Communicate with local network host via TCP / UDP --Search and advertising on Bonjour --IP multicast, broadcast, ICMP communication

NeedLocalNetworkPermission.png

What the developer needs to change

When using a local network, what you need as a developer is as follows.

1. Add a description for the local network permission dialog

The following dialog will be displayed when the app requires permission for the local network. If nothing is set, you will see a standard description of the figure, such as Introduction. You can add a descriptive text to this dialog by putting a descriptive text in ʻInfo.plist`. You can explain to your users why your app needs it.

LocalNetworkPermission説明文.png

Specifically, edit ʻInfo.plist in Xcode and the value of Privacy --Local Network Usage Description` will add a descriptive text. Info.plist.png

The file of ʻInfo.plist` is as follows.

Info.plist


<key>NSLocalNetworkUsageDescription</key>
 <string>Please describe in this part.</string>

2. Addition of services to search by Bonjour

When searching for a service in Bonjour, enter the service name to be searched in ʻInfo.plist. The services listed here will be discoverable by Bonjour. Edit ʻInfo.plist in Xcode and add the service to search to Bonjour services. Since it is an array, you can list more than one.

Bonjour.png

Info.plist


<key>NSBonjourServices</key>
<array>
 <string>_ipp._tcp.</string>
 <string>_printer._tcp.</string>
</array>

3. When broadcast / multicast communication is required

Multicast Networking Entitlement application

If you need broadcast / multicast communication other than the above, you need to apply to Apple for each app ID. Specifically, ["Multicast Networking Entitlement Request"] You can apply from (https://developer.apple.com/contact/request/networking-multicast). iOS simulators and iPad OS simulators can communicate without this permission. However, on the actual machine, communication is not possible without this permission. If you can communicate with the simulator but not with the actual device, please check if this permission is required.

Setting method after acquiring Multicast Networking Entitlement

After getting the Multicast Networking Entitlement from Apple, some settings are needed. I will write the setting method.

Addition of Capabilities for target apps (Apple Developer)

Select the target app ID. Specifically, select the target app from ʻIdentifiers of Certificates, Identifiers & Profiles` of Apple Developer in the figure below. The current URL is https://developer.apple.com/account/resources/identifiers/list.

Identifiers.png

After selecting the target app ID, you can change the app settings with ʻEdit your App ID Configuration. For apps that have acquired Multicast Networking Entitlement, you will be able to select ʻAdditional Capabilities as shown in the figure below, so select Multicast Networking.

Capability.png

Addition of Capabilities for target apps (Apple Developer)

Select the file with app name.entitlements in Xcode. Put com.apple.developer.networking.multicast in key and 1 in value as shown in the figure below. This completes the Capability settings.

entitlements.png

It is the description method in the following file.

app name.entitlements


<key>com.apple.developer.networking.multicast</key>
<true/>

References

--[To use a multicast network with the app] (https://developer.apple.com/jp/news/?id=0oi77447)

Recommended Posts

Using a local network on iOS 14
Run a simple model made with Keras on iOS using CoreML
Build a test flow on CircleCI using Jib
Try local file search using Fess on CentOS7
Try local file search using Fess on CentOS8
Build a streaming server on your iOS app
Implement common processing using method swizzling on iOS
Create a Java development environment using jenv on Mac
Using JDBC on Linux
Creating a local repository
I tried using Log4j2 on a Java EE server
Creating a docker host on AWS using Docker Machine (personal memorandum)
Draw a line on an existing PDF document using PDFBox
[Swift 5] Select a date with the IDate Picker on iOS14
Try launching a webAP server on the micro using Helidon
Try Hello World using plain Java on a Docker container
Launch a terminal on VScode
Creating a calendar using Ruby
[IOS] canOpenURL becomes false on iOS14
Create a fortune using Ruby
Post a video on rails
ATDD development on iOS (basic)
Make a rhombus using Java
Be careful when upgrading Tomcat on a Web system using Oracle
How to run a mock server on Swagger-ui using stoplight/prism (using AWS/EC2/Docker)
NLP4J [001a] Morphological analysis in Java (using Yahoo! Developer Network Japanese morphological analysis)
Easily set up a Jenkins server on AWS using Bitnami's AMI