The app I am working on involves any 2 iOS devices communicating with each other for extended period until the user wishes to end it (roughly comparable to VoIP). I am having a very hard time maintaining the connection between 2 devices as eventually one of devices will lose wifi intermittently.
The app uses UDP socket to communicate.
The list of things I have tried and checked but not working include:
- Application uses wifi key is set to YES
- Using Reachability APIs to detect wifi loss to restart later when wifi is regained – this is not working for me as the app is sent to background once wifi is lost and there is no more audio playing
I am now wondering how other such apps manage to maintain the connectivity, especially the ones that might require running overnight.
Any help greatly appreciated. I am up against the wall with this issue.
Thanks!
Here is a excerpt of console log that may be relevant:
Aug 28 23:12:10 unknown wifid[13] <Error>: WiFi:[367913530.830882]: Processing link event DOWN
Aug 28 23:12:11 unknown kernel[0] <Debug>: Removing any beacons matching: @ 0xc140a400, BSSID = 90:84:0d:dc:46:53, rssi = -64, rate = 54 (100%), channel = 10, encryption = 0x8, ap = 1, failures = 0, age = 7529, ssid[12] = "Studio"
Aug 28 23:12:11 unknown kernel[0] <Debug>: Also removing matching beacon: @ 0xc140a400, BSSID = 90:84:0d:dc:46:53, rssi = -64, rate = 54 (100%), channel = 10, encryption = 0x8, ap = 1, failures = 0, age = 7529, ssid[12] = "Studio"
Aug 28 23:12:11 unknown kernel[0] <Debug>: AppleBCMWLAN Left BSS: @ 0xc140a400, BSSID = 90:84:0d:dc:46:53, rssi = -64, rate = 54 (100%), channel = 10, encryption = 0x8, ap = 1, failures = 0, age = 7529, ssid[12] = "Studio"
Aug 28 23:12:11 unknown kernel[0] <Debug>: AirPort: Link Down on en0. Reason 1 (Unspecified).
Aug 28 23:12:12 unknown configd[45] <Notice>: network configuration changed.
Aug 28 23:12:12 unknown UserEventAgent[12] <Warning>: DEBUG: Changing WiFi state: 0
Aug 28 23:12:12 unknown CommCenter[57] <Notice>: Client [com.apple.persistentconnection[apsd,50]] is telling PDP context 0 to go active.
Aug 28 23:12:12 unknown CommCenter[57] <Notice>: No more assertions for PDP context 0. Returning it back to normal.
Aug 28 23:12:12 unknown CommCenter[57] <Notice>: Scheduling PDP tear down timer for (367913832.324872) (current time == 367913532.324882)
Aug 28 23:12:13 unknown mDNSResponder[34] <Error>: mDNS_Execute: SendResponses didn't send all its responses; will try again in one second
Aug 28 23:12:14 unknown wifid[13] <Error>: WiFi:[367913534.115957]: Processing link event UP
Aug 28 23:12:14 unknown kernel[0] <Debug>: AppleBCMWLANCore::setASSOCIATE() [wifid]: lowerAuth = AUTHTYPE_OPEN, upperAuth = AUTHTYPE_WPA2_PSK, key = CIPHER_PMK , don't disassociate .
Aug 28 23:12:14 unknown kernel[0] <Debug>: [31834.320185375]: AppleBCMWLANNetManager::prepareToBringUpLink(): Delaying powersave entry in order to get an IP address
Aug 28 23:12:14 unknown kernel[0] <Debug>: AppleBCMWLAN Joined BSS: @ 0xc22d4400, BSSID = 90:84:0d:dc:46:53, rssi = -67, rate = 54 (100%), channel = 10, encryption = 0x8, ap = 1, failures = 0, age = 1, ssid[12] = "Studio"
Aug 28 23:12:14 unknown kernel[0] <Debug>: AirPort: Link Up on en0
Aug 28 23:12:14 unknown kernel[0] <Debug>: en0: BSSID changed to 90:84:0d:dc:46:53
Aug 28 23:12:14 unknown kernel[0] <Debug>: AppleBCMWLANJoinManager::handleSupplicantEvent(): status = 6, reason = 0, flags = 0x0, authtype = 0, addr = 90:84:0d:dc:46:53
Aug 28 23:12:14 unknown mDNSResponder[34] <Error>: mDNS_Execute: SendResponses didn't send all its responses; will try again in one second
Aug 28 23:12:15 unknown configd[45] <Notice>: Captive: en0: Not probing 'Studio' (protected network)
Aug 28 23:12:15 unknown kernel[0] <Debug>: [31835.475445625]: AppleBCMWLANNetManager::receivedIPv4Address(): Received address 10.0.1.3, entering powersave mode 2
Aug 28 23:12:15 unknown configd[45] <Notice>: network configuration changed.
Aug 28 23:12:15 unknown configd[45] <Notice>: network configuration changed.
Aug 28 23:12:15 unknown UserEventAgent[12] <Warning>: DEBUG: Changing WiFi state: 1
Message was edited by studiosutara on 8/31/12 at 12:21 PM
Turns out the problem was indeed that the OS would kick in(more often in the night) and turn off the wifi to save battery. The data was being forced through the WWAN interface(this I was able to deduce from the Reachability APIs).
“Connected” UDP sockets were the answer. Since I am using CocoaAsyncSockets, I had to make the following call on the socket:
This seems to have solved the issue. The app now runs consistently without dropping wifi connectivity.