NSURLConnection 在 iphone 3gs 中发布大型视频数据失败
Posted
技术标签:
【中文标题】NSURLConnection 在 iphone 3gs 中发布大型视频数据失败【英文标题】:NSURLConnection posting large video data failing in iphone 3gs 【发布时间】:2012-10-16 12:57:04 【问题描述】:我正在尝试在 iphone 3gs 中使用 nsurconnection 上传大型视频文件。但它失败了。应用程序崩溃而没有任何日志。相同的代码在 iphone4 中运行良好。我想知道这是否是一些内存限制问题。 3gs 正在上传具有相同代码的小视频。它仅适用于大尺寸视频
这是我使用的代码:
NSMutableURLRequest *request=[[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString: urlString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:6000.0];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded; boundary=AaB03x" forHTTPHeaderField:@"Content-Type"];
NSLog(@"VideoPathD:%@",videoPathUrl);
NSError *error;
[request setHTTPBody: [NSData dataWithContentsOfURL:videoPathUrl options:0 error:&error]];
[NSURLConnection connectionWithRequest:request delegate:self];
【问题讨论】:
【参考方案1】:您是否尝试过流式传输 HTTP 正文,而不是使用 NSData
?
替换
[request setHTTPBody: [NSData dataWithContentsOfURL:videoPathUrl options:0 error:&error]];
与
NSInputStream *videoStream = [[[NSInputStream alloc] initWithURL:videoPathUrl] autorelease];
[request setHTTPBodyStream:videoStream];
【讨论】:
以上是关于NSURLConnection 在 iphone 3gs 中发布大型视频数据失败的主要内容,如果未能解决你的问题,请参考以下文章
NSURLSession与NSURLConnection区别
如何在情节提要中使用 NSURLConnection 下载文件
有啥方法可以强制异步 NSURLConnection 在后台调用 connectionDidFinishLoading 吗?