Support WiFi connection even iPad goes to sleep / locked in iOS 5

I know that on iOS 4 , the Wi-Fi connection was always constant, so going to sleep / blocking supported the connection.

This has been changed in the next version of iOS 5 to improve battery life.

In iOS 5 , requiring the device to be connected to a power source in order to have a permanent Wi-Fi connection.

The Wi-Fi connection is automatically disconnected after the iPad goes into sleep mode / locked.

Here is my problem, I am sending a large chunk of data via WiFi, which may take too long. Therefore, the user must wait for the transaction to complete.

The iPad may switch to hibernation / block, and the sending process takes longer, which will result in a WiFi connection error.

Now I set UIRequiresPersistentWiFi to YES in info.plist. However, the same network problem repeated.

I would like to maintain / constantly support the WiFi connection, even the iPad goes into sleep mode / locked in iOS5 . So, are there any alternatives to achieve this.

Thank.

+1
source share
3 answers

Phew ... Finally, I got a solution with . idleTimerDisabled

Its boolean value that determines whether the idle timer is disabled for the application.

iPad .

NO. - , " sleep", .

. , , , , , YES, " idle timer", .

YES, WiFi NO, .

: [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

. reset , .

+1

, iOS Wi-Fi. , , iPad ( 5 ). . iOS 4 Wi-Fi , ( ). iOS 5, , , Wi-Fi.

0

, , , , UIApplication beginBackgroundTaskWithExpirationHandler:?

You can do something line by line:

//#1 - Start a chunk of work as able to run in the "background"
UIApplication *app = [UIApplication sharedApplication];

bgTask_ = [app beginBackgroundTaskWithExpirationHandler:^{
    if (bgTask_ != UIBackgroundTaskInvalid) {

        //cancel the connection/load/chunk of work/operation
        [self cancelLoad];

        [[UIApplication sharedApplication] endBackgroundTask:bgTask_];
        bgTask_ = UIBackgroundTaskInvalid;
    }
}];

//#2 - Do work...

//#3 - Once work is finished, Explicity finish the background task
UIApplication *app = [UIApplication sharedApplication];

if (bgTask_ != UIBackgroundTaskInvalid) {
    [app endBackgroundTask:bgTask_];
    bgTask_ = UIBackgroundTaskInvalid;
}

You can also call # 3 in another method, because you can perform asynchronous operations (which run in the background and invoke messages asynchronously). You can also view the documentation for the 'beginBackgroundTaskWithExpirationHandler: `on white papers for more details.

Hope this helps! :)

0
source

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


All Articles