在 WiFi 重新连接和设备重新启动 (iOS) 上维护 VoIP 套接字?

发布于 2025-01-01 23:56:16 字数 133 浏览 4 评论 0原文

我有一个 VoIP 套接字设置,即使在暂停状态下也能正常工作,并且每 10 分钟 ping 一次服务器。

但是当 WiFi 连接断开时,即使处于暂停状态,我也不知道如何重新连接到该服务。设备重启也是如此。

有什么经验吗?

I have a VoIP socket setup, it works properly even in suspended states, and pings server in every 10 minute.

But when the WiFi connection has broken, then I have no idea how to reconnect to the service, even in suspended state. The same goes for device restart.

Any experiences?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

走野 2025-01-08 23:56:16
  1. 不良 WiFI:iOS 不允许您选择绑定到套接字的网络,这意味着:
    • 如果设备只有 2G/3G/4G 网络,它将绑定您的套接字。
    • 如果您也有 WiFi(也有损坏的 WiFi),它会将您的套接字绑定在其上,即使这对您不利。
  2. 重新连接:您可以在 UIApplication 中使用 10 分钟 KeepAlive 块,以便尝试每 10 分钟修复一次连接:每 10 分钟唤醒一次并尝试重新连接。
  3. 应用程序自动启动:设备重新启动后,VoIP 应用程序确实会运行(如果它在重新启动之前运行)。 (此 VoIP 应用程序权限还会在崩溃后启动您的应用程序)
  4. 注意:您可以通过在 applicationDidFinishLaunching 中询问 UIApplication 其 applicationState 来检测您是否自动启动嗯>。
  5. 提示:在后台执行操作时使用后台任务
  6. 链接:
  1. Bad WiFI: iOS doesn't let you choose the network to bind to your socket, meaning:
    • If the device has only 2G/3G/4G network, it will bind your socket over it.
    • If you also has WiFi (also broken WiFi) it will bind your socket over it even though its bad for you.
  2. Reconnecting: You may use your 10 minutes KeepAlive block in UIApplication in order to try and fix your connection every 10 minutes: Wake up every 10 minutes and try to reconnect.
  3. App launched automatically: After device reboot, VoIP app DOES get to run, if it ran before the reboot. (This VoIP app privilegue also launch your app after a crash)
  4. Note: You can detect if you were launched automatically by asking UIApplication its applicationState, in applicationDidFinishLaunching.
  5. Tip: Use Background tasks while performing actions at background.
  6. Links:
憧憬巴黎街头的黎明 2025-01-08 23:56:16

如果设备重新启动,则无法再次启动您的应用程序。用户必须启动您的应用程序。

当您的连接由于某种网络错误而断开并且您的应用程序在后台运行时,iOS 将暂停您的应用程序。因此,用户必须再次启动应用程序才能使其正常工作。

Well if the device gets restarted there is no way to start your app again. The user will have to start your app.

When you connection get dropped, due to som kind of netwerk error and your app is running in the background iOS will suspend your app. Thus the user will have to start the app again to get this working.

失去的东西太少 2025-01-08 23:56:16

setKeepAliveTimeout:handler:

为 VoIP 应用程序配置定期处理程序。

  • (BOOL)setKeepAliveTimeout:(NSTimeInterval)超时处理程序:(void (^)(void))keepAliveHandler

参数

timeout

应唤醒应用程序以检查其 VoIP 连接的最大间隔(以秒为单位)。可接受的最小超时值为 600 秒。
保持活动处理程序
执行维护 VoIP 网络连接所需任务的块。将此参数设置为 nil 会释放当前处理程序块并阻止 UIKit 安排下一次唤醒。

返回值

如果处理程序已安装,则返回 YES;如果未安装,则返回 NO。

讨论

IP 语音 (VoIP) 应用程序可以使用此方法安装处理程序,该处理程序的任务是维护应用程序与 VoIP 服务器的网络连接。该处理程序保证在指定的超时值之前被调用,但可能会以稍微不同的时间间隔调用,以便更好地使处理程序的执行与其他系统任务保持一致,从而节省电量。您的处理程序最多有 10 秒的时间来执行任何所需的任务并退出。如果在时间到期之前未退出,则应用程序将被挂起。

超时值和处理程序在应用程序启动之间不会保留。因此,如果您的应用程序因任何原因终止,您必须在下一个启动周期重新安装处理程序。

为了成功调用此方法,应用程序必须在与其 Info.plist 文件中的 UIBackgroundModes 键关联的数组中包含 voip 值。调用此方法将替换以前安装的处理程序和超时值(如果有)。

可用性

适用于 iOS 4.0 及更高版本。

中声明

在UIApplication.h

setKeepAliveTimeout:handler:

Configures a periodic handler for VoIP applications.

  • (BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void (^)(void))keepAliveHandler

Parameters

timeout

The maximum interval (measured in seconds) at which your application should be woken up to check its VoIP connection. The minimum acceptable timeout value is 600 seconds.
keepAliveHandler
A block that performs the tasks needed to maintain your VoIP network connection. Setting this parameter to nil releases the current handler block and prevents UIKit from scheduling the next wake.

Return Value

YES if the handler was installed or NO if it was not.

Discussion

A voice-over-IP (VoIP) application can use this method to install a handler whose job is to maintain the application’s network connection with a VoIP server. This handler is guaranteed to be called before the specified timeout value but may be called at a slightly different time interval in order to better align execution of your handler with other system tasks, and thereby save power. Your handler has a maximum of 10 seconds to perform any needed tasks and exit. If it does not exit before time expires, the application is suspended.

Timeout values and handlers are not persisted between application launches. Therefore, if your application is terminated for any reason, you must reinstall the handler during the next launch cycle.

For calls to this method to succeed, the application must have the voip value in the array associated with the UIBackgroundModes key in its Info.plist file. Calling this method replaces the previously installed handler and timeout values, if any.

Availability

Available in iOS 4.0 and later.

Declared In

UIApplication.h

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文