SIGPIPE error in iOS4 when app is running background and lock screen

拜拜、爱过 提交于 2019-12-04 14:38:43

问题


I use BSD socket in my app to send and receive data on iphone4(iOS4.1),there are three situations in my app:

  1. app is running in foreground and screen locks, it's fine.
  2. app is running in background and screen does't lock, it's fine too(I use NSStream to send and receive data for keep app alive in background,it works fine.)
  3. app is running in background and screen locks, app running fine but always get the SIGPIPE error when app try to call sendto() or send() through UDP or TCP socket.

I search a lot but get nothing useful,from here i know what SIGPIPE is , and i use setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(int)) to avoid app exit abnormally. but i still don't know why this error occurred only in situation 3 and how to send data normally through bsd socket in this situation.


I have try to renew and reconnect but it does't work,it still get SIGPIPE error. I think it maybe that all BSD sockets cannot get internal access in situation 3(As far as we know that BSD socket cannot activate wifi or EDGE connection in iOS),Anyone can help me or give me some suggestions? and sorry for my Broken English^.^,Thank you very much .


回答1:


I search on google and found my own question 10 months before, that's interesting. I already had a solution for application keep running in background , and setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(int)) is useful which will ignore Sigpipe 13 error .

this error happens when the socket already lost physical connection and still try to write data,through Wifi, 3G or Accessory.



来源:https://stackoverflow.com/questions/4085368/sigpipe-error-in-ios4-when-app-is-running-background-and-lock-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!