如何实现任务完成 [英] How to implement Task completion

查看:102
本文介绍了如何实现任务完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任务完成 - 应用程序可以要求系统额外的时间来完成给定的任务。

Task completion — applications can ask the system for extra time to complete a given task.

我使用此方法完成任务,

I am using this method for Task Completion,

- (void)applicationDidEnterBackground:(UIApplication *)application 
{
    UIApplication  *app = [UIApplication sharedApplication];
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^
    { 
         NSLog(@"This is Testing");

        [app endBackgroundTask:bgTask]; 

        bgTask=UIBackgroundTaskInvalid;
    }];
}

但我没有从这个方法得到任何输出。任何人告诉我,我做错了。您可以告诉任何最好的方法来完成任务。

But i am not getting any output from this method. Anyone tell me, what i am doing wrong.Can you tell any best method to implement for the task completion.

回答:

Arunkumar.P

Arunkumar.P

推荐答案

您正在设置一个过期处理程序,做什么在背景中。看起来您上面的代码是从在iOS应用程式编排指南的背景执行程式码区段。该exxample中的下一段代码是:

You are setting up an expiration handler, but you don't appear to be actually doing anything in the background. It looks like the code you have above is copied from the Executing Code in the Background section of the iOS app programming guide. The next piece of code in that exxample is:

// 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;
});

到期处理程序将不会被调用,直到时间限制(10分钟,达到;您在异步分发的任务中执行工作,而不是在到期处理程序中。

The expiration handler won't be called until the time limit (10 minutes, last time I checked) is reached; you do the work in the task that you dispatch asynchronously, not in the expiration handler.

这篇关于如何实现任务完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆