Need more ideas: How to check if iPhone is in Wifi

1.6k views Asked by At

i have a Debian server. This server should check if iPhones available in my home wifi. The problem is, that i-Devices suspend the wifi module to safe power if mobile data is available. So one solution is, just turn off mobile data and discovery in wifi works fine. (But this is not a real solution for me, because it is annoying to do this manually every time you are at home and other people will use this software, too.)

Tested so far with a iPad Mini and a iPhone5 (ios7):

  1. I have done the task for android, in Android there is a broadcast if my network connectivity change, so i just have to catch the broadcast programmatically and register me on my Debianbox. Tried the same on the iDevice but it seems not possible to intercept Wifi-Status-Changes in Objective-C in Background. In foreground its possible through the Apple-Reachability-Class. But I need it in Background, so this is not possible for me.

  2. Scan all Ports of my iPhone and try to do requests with the hope that this wake up my Wifi-Module:

    • Open UDP Ports:

      • PORT STATE SERVICE VERSION
      • 999/udp open|filtered applix
      • 1090/udp open|filtered ff-fms
      • 5001/udp open|filtered commplex-link
      • 5353/udp open|filtered zeroconf
      • 18134/udp open|filtered unknown
      • 19141/udp open|filtered unknown
      • 19717/udp open|filtered unknown
      • 20919/udp open|filtered unknown
      • 21354/udp open|filtered unknown
      • 31625/udp open|filtered unknown
      • 49191/udp open|filtered unknown
      • 57409/udp open|filtered unknown
    • Open TCP Ports:

      • PORT STATE SERVICE VERSION
      • 62078/tcp open tcpwrapped

    I tried to make requests with netcat on Port 5353 UDP (Bonjour/MDNS). The result is that the iDevices really wakes the wifi module in the first 30 Minutes! After that period of time its kind of luck if the request wake up the wifi module. I think there is maybe a "deep sleep" after about 30 minutes.

  3. MacBookPro as wifi hotspot and iDevices connected to this. Then I sniffed the whole traffic with Wireshark to check what messages are send via Wifi. At least found a MDNS multicast which is done by every iOS7 Device. This messages can be catch by a little python server. -> Works, but the period the devices sending multicasts is 1 minute up to 30+ minutes, so its not solid.

  4. A creative way: Silent Push Notification to wake up the iDevice, after that ping in wifi is possible. So the push notification just wake up my wifi! -> Works, but the APN Server don't tell you if the push-message was delivered, so its not very solid. I have tested this and some times the APN Server "swallow" the message. And every 5 minutes a internet-connectivity and mobile data traffic to check if my device is in wifi...thats not really best practice. But best solution so far for battery-life.

  5. Trigger that you are at home with a geofence region. This is possible, and works but it cost so much battery. But maybe there is no other good solution.

  6. arp-scan is a tool that makes arp-request to a ip-range. This don't work if mobile data is turned on, otherwise it does.

So my questions:

  • Is there a request on a specific port that i can send to wake up wifi-module of the iDevice?
  • Is there maybe a objective-c way to solve this task?
  • Can I send a MDNS request and the iDevice will answer it?
  • Can I create a App that has a background-listening socket and the Debianbox connect to that?
  • Any other Ideas that can solve this task? I'm out of ideas.

Thanks

2

There are 2 answers

1
Robert On

The problem is, that i-Devices suspend the wifi module to safe power if mobile data is available

I didnt read your whole question so applolgies if there is somthing you have missed, but to avoid the device from suspending the Wi-Fi after 30 mins add this key to your info.plist

UIRequiresPersistentWiFi

UIRequiresPersistentWiFi (Boolean - iOS) specifies whether the app requires a Wi-Fi connection. iOS maintains the active Wi-Fi connection open while the app is running.

0
Septronic On

Have you tried Reachability? Apple has its own framework that you can use. Try this sample by them: https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html

Hope this answers your question.