IPhone lock disables sockets only on iOS 5

I am working on a socket based application.

When a user starting any iDevice in iOS 4, 4.2.1, 4.3.2, etc., presses the lock button when connecting to the server, the connection remains alive.

However, when I press the lock button on any device running iOS 5, the connection is terminated immediately, and after returning to the application from the lock screen, I see my NSAlertView, which is called when the NSStreamEventErrorOccurred method is called.

I had several clients testing the application, and each of them with iOS 5 has the same problem - regardless of the device (iPod 2g, iPod 4g, iPhone 3GS, iPhone 4).

Have there been any changes regarding how iOS 5 devices handle locks? How can i fix this?

EDIT:

I should mention that the project was launched in Xcode 4 (iOS 4 sdk) and is now used in Xcode 4.2. I donโ€™t know if it matters or not.

+4
source share
2 answers

Like in the comments, iOS 5 has a new โ€œfeatureโ€ that sends the app to the background when the user locks the device, which actually kills network activities.

Use beginBackgroundTaskWithExpirationHandler: to mark critical sections of code that need socket access. This should allow the code to work while the application is in the background for a short while. Remember to call endBackgroundTask when you are done.

+1
source

Actually, I donโ€™t think that in iOS 5, when you lock the device, the active application will be sent to the background, it will just become inactive. I conducted several tests, if you downloaded the network boot, and then send the application to the background, the network socket will not be killed, but suspended. you can wait 10+ seconds (10 seconds is assumed by default when your application is paused before your application is paused in the background), and then return the application to the foreground, you will see that the resume resumes in the middle of the path. Although if you lock the device and immediately unlock, you will encounter a network error because your socket has been disconnected. This suggests that ios 5 does not just send your application to the background when the device is locked, it will also immediately disconnect your network socket (using an extended background job probably won't help you)

0
source

Source: https://habr.com/ru/post/1383083/


All Articles