Reputation: 123
I Write the below code for executing a task when application is in background state it is working fine in iOS 7 but it is not working in iOS 8. Can someone give me solution to execute a task continuously in iOS 8 when application is in background state.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
}
Upvotes: 3
Views: 1827
Reputation: 3288
yes i have implement the background condition while implementing ibeacon. delegate was set in interface
@interface HomeMainVC ()<ESTBeaconManagerDelegate>{
and i was able to send local notification if user enters or exist the beacon region throug following function. So there must be some way to send user location to.
//Beacon manager did enter region
- (void)beaconManager:(ESTBeaconManager *)manager didEnterRegion:(ESTBeaconRegion *)region
{}
//Beacon Manager did exit the region
- (void)beaconManager:(ESTBeaconManager *)manager didExitRegion:(ESTBeaconRegion *)region
{}
You have used following code but it is called only once when application is send to background mode so there is no use of it for you. If you want to do some things only once a time while going in background mode then it is useful for you.
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgTask;
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
}
Upvotes: 0
Reputation: 4244
There is no way to execute task continuously in background (except in few cases).
Most apps can move to the extended state easily enough but there are also legitimate reasons for apps to continue running in the background. The techniques offered by iOS fall into three categories:
- Apps that start a short task in the foreground can ask for time to finish that task when the app moves to the background.
- Apps that initiate downloads in the foreground can hand off management of those downloads to the system, thereby allowing the app to be suspended or terminated while the download continues.
- Apps that need to run in the background to support specific types of tasks can declare their support for one or more background execution modes.
For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:
- Apps that play audible content to the user while in the background, such as a music player app
- Apps that record audio content while in the background
- Apps that keep users informed of their location at all times, such as a navigation app
- Apps that support Voice over Internet Protocol (VoIP)
- Apps that need to download and process new content regularly
- Apps that receive regular updates from external accessories
Apps that implement these services must declare the services they support and use system frameworks to implement the relevant aspects of those services. Declaring the services lets the system know which services you use, but in some cases it is the system frameworks that actually prevent your application from being suspended.
Upvotes: 4