0

我正在开发的应用程序涉及任何 2 个 iOS 设备长时间相互通信,直到用户希望结束它(大致与 VoIP 相当)。我很难维持两台设备之间的连接,因为最终其中一台设备会间歇性地失去 wifi。该应用程序使用 UDP 套接字进行通信。

我尝试并检查但不起作用的事情清单包括:

  • 应用程序使用 wifi 密钥设置为 YES
  • 使用 Reachability API 检测 wifi 丢失,以便稍后在 wifi 恢复时重新启动 - 这对我不起作用,因为一旦 wifi 丢失并且不再播放音频,应用程序就会被发送到后台

我现在想知道其他此类应用程序如何设法维持连接,尤其是那些可能需要通宵运行的应用程序。

非常感谢任何帮助。我在这个问题上碰壁了。

谢谢!

以下是可能相关的控制台日志摘录:

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
4

1 回答 1

1

事实证明问题确实是操作系统会启动(更频繁地在晚上)并关闭 wifi 以节省电池。数据被强制通过 WWAN 接口(这是我能够从可达性 API 中推断出来的)。

“已连接”的 UDP 套接字就是答案。由于我使用的是 CocoaAsyncSockets,我必须在套接字上进行以下调用:

 [senderSocketName connectToHost:mPeerName onPort:[self getSocketPort] error:&socketError];

这似乎解决了这个问题。该应用程序现在可以始终如一地运行,而不会断开 wifi 连接。

于 2012-09-20T17:52:38.840 回答