Why debugging on real iOS devices does not send network packets - ios

I am developing an iOS app which requires sending UDP packets. When I test the app on the simulator, I can receive the packets from another computer. However, when I attached my phone to the computer and run it, the phone does not send out network requests.
I think the problem is that I need to let the app ask permission from the user, but I do not know how to write it.
I am sending UDP packages with using SwiftSocket, and here is my code: https://github.com/lxylxy123456/FGFS-Controller

It turns out that I cannot use an IP Address to request authorization. For my app, I can change the "IP Address" field to "apple.com" or "stackoverflow.com", and grant the APP the permission to access network, and then all data would be transferred successfully (after switching back to my IP Address).

Related

Detect when a device with a certain MAC address connects to my LAN on IOS

I am trying to trigger an event when a device with a certain MAC address connects to my LAN. Is this possible in IOS? According to some research the device I want to detect (Amazon Dash Button) performs and ARP ping to the router to connect, then triggers a hard coded HTTP request. I want to detect the ping through my IOS app so that I can trigger an event via my phone.
The most helpful resource I have found so far is this repository:
LAN-Scan
However, this is run everytime the user invokes it. Is there a way o constantly scan the local network trigger some code when a new device connects?
Any and all help is appreciated.

Is there a way to programmatically change network routes on an iOS device?

Scenario: I want to have an iOS device connect to a LAN that has no upstream Internet connection, yet still retain and use its cellular data connection.
Theoretically, it strikes me that the iOS wifi NIC and the cellular data NIC are similar enough to dual NICs in a PC that I should be able to set up routing such that any request to, say, 192.168.. goes through the wifi connection, and any other request goes through the cellular data connection.
I did a test to see if both NICs are active when the iOS device is connected to wifi by the following steps.
Ensure that my iPhone's wifi is off and that I have a good cellular data connection.
Disconnect my wifi router's Ethernet cable to my cable modem.
Connect my iPhone to the wifi router.
Use another iPhone that's connected only via cellular data to create a game of Words with Friends.
As soon as the other iPhone completed the first move, my iPhone received a notification that there was a new game to play.
This confirmed that the cellular data connection was indeed alive and well enough to receive push notifications despite the wifi NIC's being connected.
The question becomes, then, can an app programmatically connect to a given wifi network, set the cellular data network to be the default route, and route any requests to, say, 192.168.. to go through the wifi network?
I know this post is old, but I happen to have done some work on using multiple network interfaces on iOS.
My experiments showed that accessing via hostname results in iOS choosing the network interface it wants to use, and not trying any further interfaces if the host cannot be resolved.
If you know the DNS Server IP address for any Ethernet/WiFi based network, you can send a DNS request yourself, convert the hostname into an IP address and access via IP address. iOS will then use the correct interface.
My guess is, that if you have the private class IP address space accessible over both connections, there's probably nothing you can do to specify which network interface should be used.

iOS device discovery without Bonjour

I'm creating an app that needs to connect to versions of itself running on other devices on the wifi network. The goal is to set up a broadcast / client relationship between one device to the others.
I know that Bonjour is the accepted method to do this, but I'm reticent to do that because it locks me into iOS devices, when I'd like to branch out to others, at least for clients.
If I start a webserver on the broadcaster on a specific port, like 43231 or something, is it acceptable for the client device to get it's own IP and then scan that block range for the broadcaster? Is there anything bad about pinging all the other random devices on the network with a request like that?
As in, Broadcaster is 192.168.1.11. Client is 192.168.1.4. If the client assumes all the devices are in the 192.168.1.* block, can it just iterate up the line from 1-100 or so looking for the broadcaster?
If this method is crazy, what should I do?
You can use SSDP (used by UPnP) or just multicast a message over the network and listen for it at the same time, ignoring the loopback (if you don't want the sender to receive it's own messages).
Maybe it will be better to use Bluetooth Low Energy for broadcasting/discovery? You can send non-connectable advertisement packets on server (with it's IP address) and listen for them on all other devices. Device founds such packet, reads IP address and connects to it via NSURLConnection (or something like that).

"Internet connection is offline" when connecting to AP without internet access - WiFi off/on fixes

BACKGROUND
We're trying to use an iOS app running on iPhone/iPad to give WiFi credentials to an embedded device (using an ARM SoC running Linux). The embedded device starts an AP (access point), we instruct the user to connect to this AP and then the user submits their WiFi credentials. After WiFi credentials are received the device drops the AP and connects to the WiFi the user gave credentials for.
Initially, we try to hit a PHP page to get the list of WiFi networks the embedded device can see.
ISSUE
We instruct the user to join XYZ network (in iOS they must background the app, go into settings and switch to our WiFi network). We listen for an app resumed from background notification, check the devices current ESSID (ensure its our AP ESSID) and try to hit a PHP page to receive the list of WiFi networks. Often, this connection fails reports "The internet connection appears to be offline" (or something of that nature).
We currently have a stop gap when this happens telling the user to toggle their WiFi off and then back on (in settings). The device will reconnect to our AP as it's the most recently connected network. This ALWAYS fixes the issue, we've never had to toggle the WiFi twice in order to reach the PHP page on the device. Please tell me any possible way we can avoid having to instruct the user to toggle WiFi and still access PHP pages on the embedded device.
Note: when we're connected to the AP (whether this bug is active or fixed) the device DOES NOT show the WiFi icon in the status bar. We assume this is because the AP doesn't have a viable connection to the internet (can only access pages served by the embedded device). We've been testing on a device that has LTE cellular access, but the error still says "Internet connection appears to be offline".
Obviously we have a DHCP server running on the embedded device.
It's looking like this was caused by an omission in our dhcpd.conf file.
This omission was causing iOS to believe the connection was unviable.
We added the following line and are getting much better results:
option domain-name-servers 10.10.10.1;

How can I broadcast data between the same app but on different ipad's within a common LAN

I want to be able to have multiple iPads on a single LAN running the same app each with the ability for peer to peers broadcast.
This needs to be peer to peer broadcast (serverless) or if I have to, then I can designate one app as the local server to receive and resend events. But the information should never leave the LAN (so no cloud server).
A simple example would be an app that has a single button. Each instance of this app would be configured with a unique ID (say 1-10). When any user touches that button anywhere on the LAN all the other iPads running this app would display the number of the app instance elsewhere on the LAN where the button has been pushed.
This seems like it should be a basic capability but I am having a hard time finding if it is even possible in IOS. Can anyone confirm that it is and how to do it?
You could set it to broadcast on the broadcast ip of the lan. and use it like a multicast address.
ex. 192.168.1.0/24
broadcast/listen on 192.168.1.255
the only downfall is that it will be sent to every device on the lan.
[edit] vv
or if you designate one as the server you could advertise the servers ip address as a broadcast.

Resources