Reputation: 1868
I am sending some data(image bytes) from iOS app to socket server (java-desktop) in every some intervals. Its sending data properly. I am seeing a strange issue, if the iOS device screen goes off while sending the data from iOS app, and then if I screen on the device, then i get the following error and app has got disconnected with socket or sometimes it crashes the app:
Error writing to stream <__NSCFOutputStream: 0x1f5dd120>: Error Domain=NSPOSIXErrorDomain Code=32 "The operation couldn’t be completed. Broken pipe"
Stream space : 0
NSStreamEventErrorOccurred - Can not connect to the host
When the device screen turned Off, My iOS app stops sending data to socket. and then turning ON the screen back, socket connection gets disconnected / broken pipe error. How to solve it? I searched but couldn't find the solution yet. Could someone please advise what could be the reason for this issue and how to solve this?
Upvotes: 6
Views: 9042
Reputation: 265
your server might have stopped working or in stop state. Restart your server and run the application.
Upvotes: 0
Reputation: 1142
You have 2 options.
1. Disable idle timer: This code will prevent your iPhone from going to sleep while your app is running. I'm not sure if this prevents the device from locking, but you can prevent the screen from dimming with the UIApplication's idleTimerDisabled property.
[UIApplication sharedApplication].idleTimerDisabled = YES;
From the documentation:
Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.
2. Make an app with background support: You may follow this tutorial on Background Modes in iOS.
Here’s a quick overview of the five basic background modes available in iOS:
VOIP background mode allows your app to run arbitrary code while in the background. This mode is better than the “Whatever” API because you can run the code for an indefinite amount of time. Better yet, if the app crashes or the user reboots the phone, the app is started automatically in the background. If you are interested, you may follow Tips for Developing a VoIP App provided by apple. Your app needs to provide the user with some sort of VoIP functionality or Apple will reject your app.
Upvotes: 7
Reputation: 40624
You can consider disable the idleTimer until the network activity is complete
Upvotes: 1