如何在后台继续使用NSURLConnection在前台开始连接?
问题描述:
我想这个问题如何在后台继续使用NSURLConnection在前台开始连接?
的答案,就像一个魅力!但只有当设备连接我的iMac ... 一旦我断开我的iOS设备应用程序运行3分钟后,然后应用程序再次启动,这不会发生,如果iOS设备连接。 这是为什么发生?有没有办法在后台继续上传,直到10分钟的时间?
我没有实现这个代码
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// Handle the error
...
//this line
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskID];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// Save the downloaded data
...
//and this line
[[UIApplication sharedApplication] endBackgroundTask:self.backgroundTaskID];
}
答
NSURLConnection的目的不是在您的应用程序没有运行使用。在NSURLSession后台会话中使用上传任务,它将按照您的预期工作。
谢谢,我意识到应用程序运行3分钟,因为应用程序可以在后台运行,直到iOS发送应用程序进入睡眠状态,是否有任何教程或指南将NSURLConnection更改为NSURLSession? – CGR