应用程序在后台暂停后锁定手机后,AsyncUDPSocket 破坏了管道

发布于 2024-11-15 23:18:12 字数 784 浏览 7 评论 0原文

我在 iPhone 应用程序中使用 AsyncUDPSocket 第三方库,并且大部分情况下它都能正常工作伟大的。我有一个 AsyncUDPSocket 的单例实例,用于所有网络流量。我的应用程序已在后台注册位置跟踪,并将在后台运行时唤醒并通过网络发送位置更新数据包。这一切都在后台、前台、手机锁定或解锁中运行,除非我执行以下操作:

  1. 启动我的应用程序
  2. 在我的应用程序设置中禁用位置跟踪 (因此没有后台唤醒)
  3. 按主页按钮(应用程序进入后台,套接字与应用程序的其余部分“冻干”)
  4. 锁定手机
  5. 解锁手机
  6. 恢复应用程序
  7. 尝试重新启动跟踪并从套接字发送一些内容。一旦我尝试,我就会收到 SIGPIPE/EPIPE 错误,并且应用程序崩溃。

我认为处理此问题的最佳方法是每当应用程序退出且未启用后台跟踪时关闭并释放套接字,但是当我尝试 [socket close][socket release ]AsyncUDPSocket 上,我收到各种 EXC_BAD_ACCESS 错误。我已向开发团队提交了一个错误,但想知道这里是否有人可以提供一些关于如何完全避免 SIGPIPE 错误或其他方法来保持套接字处于活动状态而不释放它的想法。谢谢。

I'm using the AsyncUDPSocket third party library in my iPhone app and for the most part it works great. I have a singleton instance of an AsyncUDPSocket that I use for all my network traffic. My app is registered for location tracking in the background and will wake up and send location update packet(s) over the network while running in the background. This all works smashingly running in the background, foreground, phone locked or unlocked, except when I do the following:

  1. Start my app
  2. Disable location tracking in my app settings
    (so no background waking up)
  3. Press the home button (app goes into background, socket is "freeze-dried" with rest of app)
  4. Lock phone
  5. Unlock phone
  6. Resume app
  7. Attempt to restart tracking and send something out the socket. As soon as I try, I get a SIGPIPE/EPIPE error and the app crashes.

I figured the best way to deal with this would be to close and release the socket whenever the application exits and background tracking is not enabled, but when I try [socket close] or [socket release] on the AsyncUDPSocket, I get various EXC_BAD_ACCESS errors. I've filed a bug with the dev team, but was wondering if anyone here could give some ideas on how to either avoid the SIGPIPE error entirely or other ways to keep the socket alive without releasing it. Thanks.

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

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

发布评论

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

评论(2

一城柳絮吹成雪 2024-11-22 23:18:12

很好的观察 - 是的,似乎在你将任务发送到后台然后锁定手机后,套接字就会掉线,下次你尝试使用它时,就会被 SIGPIPE 重击。

关于如何处理它的想法在这里:
切换后台任务时 SIGPIPE 崩溃
(它要么为整个应用程序或套接字设置忽略 SIGPIPE,要么为其提供处理

程序 )另外 - 似乎设置忽略 SIGPIPE 不适用于附加的调试器,因此与 和 w/o 进行比较。

Great observation - yes, seems that after you send task to background and then lock the phone, sockets get dropped and next time you try to use it one gets bludgeoned with a SIGPIPE.

Ideas on how to deal with it here:
SIGPIPE crash when switching background task
(it's either set ignore for SIGPIPE for the whole app, or for the socket, or provide hanler for it)

ps. also - seems that setting to ignore SIGPIPE does not work with attached debugger, so compare with and w/o.

空袭的梦i 2024-11-22 23:18:12

以防万一有人好奇(从这个问题的统计数据来看,他们不是),我无法确定是什么导致了 SIGPIPE 错误,但最终解决了我的内存管理问题(这是由于我的委托中的 onUdpSocketDidClose 实现错误造成的),这样我就可以在每次应用程序重新启动时重新初始化套接字。

Just in case anyone's curious (which, judging by this question's stats, they're not), I was not able to determine what was causing the SIGPIPE error, but did eventually sort out my memory management issues (which were due to a faulty implementation of onUdpSocketDidClose in my delegate) so that I am able to reinitialize the socket each time the app restarts.

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