-(void) Applicationdidenterbackground: (uiapplication *) application
{
//Use this method to release shared resources, save user data, invalidate timers, and store enough Applicati On the state information to the restore your application to the it is terminated later.
//If Your application supports background execution, this method is called instead of Applicationwilltermina Te:when the user quits.
nsassert(self-bgtask = = Uibackgroundtaskinvalid, nil);
Self - Bgtask = [Applicationbeginbackgroundtaskwithexpirationhandler: ^{
Synchronize the cleanup call on the main thread in case
The task catully finished at around the same time.
Dispatch_async (dispatch_get_main_queue(), ^{
if (uibackgroundtaskinvalid! =self --bgtask) {
[Application endbackgroundtask:Self--bgtask];
Self - Bgtask = Uibackgroundtaskinvalid;
}
});
}];
Start the long-running task and return immediately.
Dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default ,0),
^{
// do the work assoicated with the task.
// Synchronize The cleanup all on the main thread in C Ase
// the task catully finished at around the same time.
dispatch_async ( Dispatch_get_main_queue(), ^{
NSLog(@ "Background time:%f", [[uiapplication sharedapplication] backgroundtimeremaining]);
if ( Uibackgroundtaskinvalid! =self--bgtask) {
[Applicationendbackgroundtask:Self--bgtask];
self- >bgtask =uibackgroundtaskinvalid;
}
});
});
}