// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *cameraView;
@end
NSMutableData *dataResponse; // buffer for accumulating data
====================================================
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *cameraURL = @"http://192.168.1.160:554/video.mjpg";
NSURL *url = [NSURL URLWithString:cameraURL];
NSURLRequest *requestURLcamera = [NSURLRequest requestWithURL:url]; // URL request
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:requestURLcamera delegate:self startImmediately:YES]; // connecting
}
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}
- (void)connection: (NSURLConnection *) connection didReceiveData:(NSData *)data
{ [dataResponse appendData:data]; } // accumulating data
- (void)connection: (NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)response
{ UIImage *imageZ = [UIImage imageWithData:dataResponse]; // creating image
_cameraView.image = imageZ; // image to UIImageView
dataResponse = nil; // reset of dataResponse
}
@end
dataResponse = [NSMutableData dataWithCapacity:100]; //capacity написал "от фанаря"