downloadTaskWithRequest
全部标签 先介绍一些背景:应用程序应该从AWSS3服务器获取文件。为此,该过程的第一步是转到本地服务器并从中获取文件名和其他一些信息。在该步骤之后,我们有一个完整的URLMutableRequest。注意:我正在将NSURLSession设置为后台session:-(NSURLSession*)backgroundSession{staticNSURLSession*session=nil;staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{NSURLSessionConfiguration*configuration=[NSURL
所以我很难理解某些东西。这是我对NSURSession的理解:一般来说,我有2个选项(据我所知)DataTask(e.xdataTaskWithRequest)和DownloadTask(e.xDownloadTaskWithRequest)-使用他们的委托(delegate)方法,或使用完成处理程序,不能两者都做。我已经设法使用dataTaskWithRequest接收数据,如下所示:letrequest=NSMutableURLRequest(URL:dataSourceURL!)request.HTTPMethod="POST"letpostString="lastid=\(id
所以我很难理解某些东西。这是我对NSURSession的理解:一般来说,我有2个选项(据我所知)DataTask(e.xdataTaskWithRequest)和DownloadTask(e.xDownloadTaskWithRequest)-使用他们的委托(delegate)方法,或使用完成处理程序,不能两者都做。我已经设法使用dataTaskWithRequest接收数据,如下所示:letrequest=NSMutableURLRequest(URL:dataSourceURL!)request.HTTPMethod="POST"letpostString="lastid=\(id
-(NSURLSession*)sharedBackgroundSession{staticNSURLSession*sharedBackgroundSession=nil;staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{NSURLSessionConfiguration*configuration=[NSURLSessionConfigurationbackgroundSessionConfiguration:@"com.example.apple-samplecode.SimpleBackgroundTransfe
如果我使用下面的代码aDownloadTask=[self.backgroundSessiondownloadTaskWithURL:aRemoteURL];上面代码的说明:当我使用downloadTaskWithURL开始下载时,它返回expectedContentLengthnegative(-1)但那一次恢复数据变得完美。另一个是为了解决上述问题,我使用下面的代码NSMutableURLRequest*aURLRequest=nil;aURLRequest=[[NSMutableURLRequestalloc]initWithURL:aRemoteURLcachePolicy:N