how can I use UIWebview as always working on background - iphone

I would like to set UIWebview always running on background.
UIWebview is not working when iPhone entered 'applicationDidEnterBackground'.
so I want UIWebview to run always on backgroud.
Is it possible?

Every app can continue to execute in the background for roughly 10 minutes before it terminates. Only certain apps can continue to execute in the background, such as audio/gps/bluetooth etc related apps. You can find out more here.
The following code sample is from the app doc and can help you get started -
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you.
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}

Related

Sending Local notifications when the app is in background mode not working

I want to be able to send multiple local notifications throughout the day, this must also work in background mode and it must work on a timer, so every 20 minutes to be exact. The problem I am having is that once in background mode they are not firing because the function used to set the timer will not run.
I have then thought about running the timer in the applicationDidEnterBackground but this would clash with the original timer set in the function.
Is there anyway for this to work basically? Any wisdom would be very grateful.
Try looking this link and perfrom your task in background
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [application beginBackgroundTaskWithName:#"MyTask" expirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}

Background task in objective c

I have a VOIP application in objective-c
SIP call is working fine when application is in foreground.
My problem is when my app is in background SIP call is not working after 10 minutes after going to background.
I have started a background task in applicationDidEnterBackground
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you
// stopped or ending the task outright.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
In plist file UIBackgroundModes is set to voip
I am in a patience for it.
Please any body help me. Please.
By my understanding the beginBackgroundTaskWithExpirationHandler method is used for executing a Finite-Length Task in the Background. See Here. And there is no way extend that period of 10 mins which I have discovered.
Since your app classifies as a background mode required app, I dont think you will be needing
beginBackgroundTaskWithExpirationHandler.
Read "Implementing a VoIP App" section in the above link.It advocates the use of setKeepAliveTimeout:handler: method.

Application delegates are not calling while application entered into background

I am implementing an iPhone application.I am downloading data from server by using asynchronous request in the application.If, I Press the home button, My application delegate is not calling directly.After completion of data downloading from server, application delegate methods are calling.So, How can i get the immediate Delegate call in my application.
Any help can be appreciate.
Which delegate methods are you implementing? Can you post what you've tried (code-wise) here? Note that once your application has been moved to the background, you can only run short-term tasks to preserve battery life.
This example is provided by Apple:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
// Clean up any unfinished task business by marking where you.
// stopped or ending the task outright.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task, preferably in chunks.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
If you want to perform longer running tasks, you require special permissions, and even then can only perform a certain subset of actions. They are discussed here:
iOS App Programming Guide: App States and Multitasking

Iphone: Does application freeze when run into background?

I have an application that upload file to server using NSUrlConnection. It was placed on ViewDidLoad method. It did upload to server while the application is in foreground. Before I call the NSUrlConnection asynchronously, I create temporary file in application directory.
While the files were uploading, I clicked on the iPhone button so that the application will run in the background. First thing I thought the application freeze the upload, but it doesn't. The file still uploading during that time.
Does that mean the application still running normally at the background until the remaining time finished then the application quits?
Once the home button is pressed, every application runs in the background for a certain amount of time(usually few seconds) before it enters suspended mode. If you are required to complete a task(in your case file upload) before entering suspended mode, you can use Task completion API.
Even if you are using task completion API, only one thread of your application is running, but not the whole application. Here is the code recommended by apple:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}

i want to terminate the app after some minutes while it run in background

i want to terminate the app after some minutes while it runs in background.
steps like these :
press the home button then app run in background.
2minutes later the app terminates automaticly.
i find a method as below:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Do the work associated with the task.
//============================
// here i want to add a timer
//=============================
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
as you see,
i want to add a timer in that place.
but the timer didn't work in background. i also tried the performSelector:afterdelay:
how can i do this?
After 10 minutes, All app terminates.
If you have to exit app only after 2 mins,
set timer in (applicationWillResignActive)
I suppose your app is doing some kind of work while in background - otherwise there would be no need to run it in the background in the first place.
I further suppose you have some kind of runloop going, since you'd like to terminate after a certain amount of time and not after some task has been completed.
So I'd suggest logging the system time at the moment the app goes into background and then in your runloop check for the current system time once per iteration. If it is greater than the initial time + 2 minutes, terminate background activity.