当主页按钮按下并且应用程序在背景中时,我想上传图像。 这可能吗?如果是,那么如何?如果没有,那么我有其他的选择吗? 在此先感谢...当应用程序进入后台时可以调用webRequest吗?
1
A
回答
3
您可以在后台通过使用此代码为特定的时间
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];
我认为这将帮助ü。 :)
+0
谢谢....我通过阅读苹果文档得出结论:上传过程可以在应用程序转到背景后执行最长10分钟, – 2013-03-07 09:46:55
+0
欢迎您@KhushbuPatel ..快乐编码:) – shivam 2013-03-07 10:29:56
1
应用程序可以请求在关闭后最多10分钟后在后台运行,以便它可以完成长时间运行的任务。只有一些进程被允许在后台运行。见实现长时间运行的后台任务部分in this reference.
如果您的应用允许的话,你可以试试下面的代码:
- (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
更多裁判去与这个reference PDF(page 60)
相关问题
- 1. 当应用程序进入后台并进入前台时调用UIViewController方法
- 2. 当应用程序进入后台时运行后台线程
- 3. 当应用程序进入后台时,应用程序代理不会调用
- 4. Swift - 当应用程序进入后台时进入视图
- 5. 我可以知道应用程序进入后台时按了哪个键吗?
- 6. 当应用程序进入后台时使计时器无效
- 7. 当Android应用程序从后台进入前台时如何获取回调?
- 8. 可以调用performSelectorOnMainThread:调用beginBackgroundTaskWithExpirationHandler并且应用程序在后台之后吗?
- 9. Android应用程序进入后台时能检测到吗?
- 10. 当我的应用程序进入后台时,可以将一个循环放入dispatch_async吗?
- 11. 当应用程序进入后台时取消API请求
- 12. 当应用程序进入后台时显示暂停菜单
- 13. 当应用程序进入后台时运行MPMoviePlayer
- 14. 当应用程序进入后台时关闭弹出窗口
- 15. 当应用程序进入后台时,startAdvertisingPeer是否工作?
- 16. 当应用程序进入后台时处理事件
- 17. 当应用程序进入后台模式时释放图形
- 18. 当应用程序刚进入后台时显示提醒
- 19. UIDeviceBatteryLevelDidChangeNotification当应用程序进入后台时的问题
- 20. 当应用程序进入后台时执行Segue
- 21. 当应用程序进入后台时启动JavaScript函数
- 22. 当应用程序进入后台时继续下载
- 23. 当应用程序进入后台时关闭modalviewcontroller
- 24. 当从后台调用应用程序时调用方法
- 25. 应用程序在后台运行时可以截屏吗?
- 26. Android - 应用程序的LeScanCallback会在应用程序进入暂停(到后台)时被调用吗?
- 27. Facebook应用程序进入前台后
- 28. 当应用程序在后台时NSURLConnection
- 29. 当应用程序在后台时使用iBeacon进行广告
- 30. OnDestroy()当应用程序转到后台时被调用服务
http://developer.apple.com/library/ios/#technotes /tn2277/_index.html – Desdenova 2013-03-07 09:19:29