foreplay

Apple’s iOS 14 for local LAN did some permissions, see links: developer.apple.com/videos/play…

WWDC translated to make up the word count

What is a local network?

The local network here is actually the local area network (LAN), which is formed after the device is connected to the router. Devices can communicate with each other through this network. Functions such as device discovery, device binding, and LAN priority are all used by the local network.

Starting with iOS 13, in order for an app to get the name of the Wi-Fi it’s currently connected to, it has to get location permission. Because by recognizing Wi-Fi names, apps can easily build big data networks between you and the people around you. But just because you don’t have location permission doesn’t mean the app can’t track you, because the app can track you from devices on the local network.

Why do I need to apply for permission from a user?

Similar to iOS 13, obtaining WiFi name requires location permission. Apple has strengthened user privacy security permission, which is a similar problem here. In previous versions of iOS, apps could scan devices on the local network at will, so apps could easily get the names and MAC addresses of all devices on the local network. A MAC address is an address used to identify the location of network devices. Each nic has a unique MAC address. In addition, device manufacturers assign MAC addresses according to certain rules, so that different Lans can be uniquely identified. Let’s say you buy a new camera offline, take photos and use the camera’s built-in Wi-Fi to import them to your phone. At this time, the application with a promotion module launches a scan on the LAN and identifies a new device. The promotion module will upload the MAC address of the camera to the cloud. After simple identification and comparison, it is easy to know that the MAC address belongs to the camera. Apps with a promotion module will tag you as “camera user” in the portrait, and the next time you open a shopping app with the same promotion module, you’ll see a bunch of camera-related recommendations.

Which applications need to use a local network?

  • Discover devices using the local network
  • Use the local network for data transmission
  • Network debugging tool

scope

Socket or Bonjour cannot be used for LAN discovery and data transmission.

For LAN applications such as: smart home, LAN games, network testing tools and so on. I have tested it and found that this switch may not take effect after the next startup of the App. The cause has not been identified for the time being.

How to solve it?

I believe many people are very surprised why not the entire permission application or status query interface, after turning over some information, found that there is really no. Link: developer.apple.com/forums/tags…

Very helpless!

Most applications use the local domain, usually using Socket or Bonjour for local discovery and data transfer. Code: 65 desc:no route to host desc:no route to host This is actually called no local network permission. However, I found in the test that sometimes even if the switch of local network permission is turned off, UDP and TCP can be used normally. I can’t believe it! Will iOS 14 be like iOS 13 when it started?

The idea here is

  • Obtain the IP address of the local host through the interface
  • Ping the IP of a mobile phone using SimplePing

The whole process takes about 0.13-0.2 seconds, most of which are about 0.17 seconds. It might take an acceptable amount of time. It is not known whether some routers can be set to disable ping. If there is, it will burst. Here’s the simple code

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSDictionary *router = [LDSRouterInfo getRouterInfo]; pinger = [[SimplePing alloc] initWithHostName:router[@"ip"]]; pinger.delegate = self; [self->pinger start]; } - (void)simplePing:(SimplePing *)pinger didStartWithAddress:(NSData *)address { if (timer) { return; } timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue()); dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC, 0 * NSEC_PER_SEC); dispatch_source_set_event_handler(timer, ^{ [pinger sendPingWithData:nil]; }); dispatch_resume(timer); } - (void)simplePing:(SimplePing *)pinger didSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber { NSLog(@" can use LAN "); } - (void)simplePing:(SimplePing *)pinger didFailToSendPacket:(NSData *)packet sequenceNumber:(uint16_t)sequenceNumber Error :(NSError *)error {if (error.code == 65) {//no route to host NSLog(@" do not use LAN "); }}Copy the code

Helpful hints

  • Setting the above interface triggers the system popup for the first time enabling local network permissions
  • I wonder if some routers can be set to disable ping
  • The process takes 130-200 milliseconds on the iPhone 6SP. The average is around 160 milliseconds
  • The above code is not officially online, I am also testing, please use as appropriate.

demo