我正在使用NSInputStream以下列方式将媒体文件上传到服务器。
uploadInputStream = [[NSInputStream alloc] initWithFileAtPath:videoFilePath];
uploadInputStream.delegate = self;
[uploadInputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[uploadInputStream open];
在NSStream委托方法流:handleEvent:我正在获取媒体文件块并上传到服务器。
- (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode {
switch (eventCode) {
case NSStreamEventOpenCompleted:
NSLog(@"Strem opened");
break;
case NSStreamEventHasBytesAvailable: {
uint8_t buf[1024*1024];
unsigned int len = 0;
len = [(NSInputStream *)aStream read:buf maxLength:1024*1024];
if(len)
{
@autoreleasepool {
NSMutableData *fileData = [NSMutableData data];
[fileData appendBytes:(const void *)buf length:len];
[self uploadVideo:fileData];
}
}
break;
}
case NSStreamEventHasSpaceAvailable:
break;
case NSStreamEventEndEncountered: {
break;
}
case NSStreamEventErrorOccurred:
break;
case NSStreamEventNone:
break;
default:
break;
}
}
到目前为止一切都那么好,一切都在模拟器中运行良好。问题是如果我在真实设备(iPad-mini for now)中测试相同的代码,它总是在陈述委托方法流时,使用EXC_BAD_ACCESS代码= 1使应用程序崩溃:handleEvent:。
有人对此有任何想法吗?任何帮助将不胜感激。
谢谢, 杰伊斯蒂芬。