如何实现任务完成
任务完成——应用程序可以要求系统额外的时间来完成给定的任务。
我正在使用此方法来完成任务,
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^
{
NSLog(@"This is Testing");
[app endBackgroundTask:bgTask];
bgTask=UIBackgroundTaskInvalid;
}];
}
但我没有从该方法中获得任何输出。任何人告诉我,我做错了什么。你能告诉我完成任务的最佳方法吗?
问候,
Arunkumar.P
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.
Regards,
Arunkumar.P
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在设置一个过期处理程序,但您似乎并未在后台实际执行任何操作。看起来您上面的代码是从
在达到时间限制(10 分钟,我上次检查时)之前,不会调用过期处理程序;您在异步分派的任务中完成工作,而不是在过期处理程序中完成。
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:
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.
这解决了我的问题:iOS 4 中的简单后台任务。
主要思想是调度一个不执行任何操作的异步执行代码,但允许当前代码继续运行。
希望它也能解决你的问题!
This solved my problem: Easy Background Tasks In IOS 4.
The main idea is to dispatch an async execution code that does nothing, but allows your current code to keep running.
Hope it solves yours too!