![](/img/trans.png)
[英]MPMoviePlayer play on when application goes Background when incoming call is coming
[英]Is it possible to call webRequest when application goes in background?
我想在按下主页按钮和应用程序进入后台时上传图像。 可能吗? 如果是,那怎么样? 如果没有那么我还有其他选择吗? 提前致谢...
您可以在特定时间内使用此代码在后台执行任务 -
UIBackgroundTaskIdentifier bgTask = 0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
self.silenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self
selector:@selector(startLocationServices) userInfo:nil repeats:YES];
请参阅: http : //developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html
我想这会对你有所帮助。 :)
应用程序可以在关闭后请求在后台运行最多10分钟,以便它可以完成长时间运行的任务。 只允许某些进程在后台运行。 请参阅本参考中的 实现长时间运行的后台任务部分。
如果允许您的应用,您可以尝试下面的代码:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIBackgroundTaskIdentifier bgTask;
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;
});
}
如果您想知道您的应用程序剩余运行的时间
NSTimeInterval ti = [[UIApplication sharedApplication]backgroundTimeRemaining];
NSLog(@"Remaining Time: %f", ti); // just for debug
有关更多参考,请参阅此参考PDF(第60页)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.