应用程序在后台暂停后锁定手机后,AsyncUDPSocket 破坏了管道
我在 iPhone 应用程序中使用 AsyncUDPSocket 第三方库,并且大部分情况下它都能正常工作伟大的。我有一个 AsyncUDPSocket
的单例实例,用于所有网络流量。我的应用程序已在后台注册位置跟踪,并将在后台运行时唤醒并通过网络发送位置更新数据包。这一切都在后台、前台、手机锁定或解锁中运行,除非我执行以下操作:
- 启动我的应用程序
- 在我的应用程序设置中禁用位置跟踪 (因此没有后台唤醒)
- 按主页按钮(应用程序进入后台,套接字与应用程序的其余部分“冻干”)
- 锁定手机
- 解锁手机
- 恢复应用程序
- 尝试重新启动跟踪并从套接字发送一些内容。一旦我尝试,我就会收到
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:
- Start my app
- Disable location tracking in my app settings
(so no background waking up) - Press the home button (app goes into background, socket is "freeze-dried" with rest of app)
- Lock phone
- Unlock phone
- Resume app
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很好的观察 - 是的,似乎在你将任务发送到后台然后锁定手机后,套接字就会掉线,下次你尝试使用它时,就会被 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.
以防万一有人好奇(从这个问题的统计数据来看,他们不是),我无法确定是什么导致了
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 ofonUdpSocketDidClose
in my delegate) so that I am able to reinitialize the socket each time the app restarts.