无法更新UIImageView

时间:2016-07-09 18:43:16

标签: objective-c uiimageview nsurlconnection

我试图通过本地IP将MJPEG视频流式传输到我的iOS应用中。建立连接并且流成功,我可以在控制台中看到十六进制值更新。但是,UIImageView仅显示它收到的第一帧,之后不会更新。代码什么错了?我甚至尝试使用setNeedsDisplay刷新视图,但它没有帮助。我知道在iOS 9+中不推荐使用NSURLConnection,这只是为了测试代码,以便如何解决这个问题?

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize recievedData;

- (void)viewDidLoad {
    NSURLRequest *theRequest =
    [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.15:8090/?action=stream"]];
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    recievedData = [[NSMutableData alloc] init];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [recievedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"%@",recievedData);

    UIImage *recievedImage = [UIImage imageWithData:recievedData];
    self.streamView.image = recievedImage;
        [self.streamView setNeedsDisplay];


}

@end

1 个答案:

答案 0 :(得分:0)

我认为这是视频流,您需要使用视频播放器来显示媒体内容。