0

I'm new to objective-C and completely self taught, so i could be making a very obvious mistake, but to my knowledge i'm following the AVFoundation programme guide directly and it raises errors that the guide doesn't warn me about.

I've found solutions to the "initialiser element is not a compile-time constant" error elsewhere on the site, but none have worked for me. And i'm not even sure why i'm getting this error in the first place: the guide doesn't say that the code should be inside a function, or does it just assume that i know that already? When i put it inside a function or method, the error warnings disappear, but the app will not load properly on my phone; after the launch screen the storyboard just goes black - unless there is something wrong with how i've added the input to the session? but again, i followed the guide. Here is the code i used:

// set up session

AVCaptureDevice *camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:camera error:nil];
AVCaptureSession *session = [[AVCaptureSession alloc]init];
[session addInput:input];
session.sessionPreset = AVCaptureSessionPresetHigh;

// display preview

AVCaptureVideoPreviewLayer *preview = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
CALayer *viewlayer = preview;
[viewlayer addSublayer:preview];

The error occurs on camera, input, session, preview, and view layer. I've tried putting it all in a function then calling it, but this causes the app to crash. I've tried initialising the five variables as nil and then redefining, but this just raises a different, redefinition error, i've tried putting it in methods, in 'view did load'... i don't have that much experience and i'm running out of ideas.

Here's the link to the AvFoundation guide i used in case you can spot something i can't: https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW14

Thank you, any suggestions are much appreciated, I've been stuck on this for two weeks and I'm getting really behind on my project.

katewall
  • 1
  • 3
  • Is input a member variable? Because if so, there shouldn't be a `*` in front of it. – dudeman Jul 27 '15 at 16:42
  • Sorry there was a typo there MikeAtNobel, input was meant to be an instance of AVCaptureDeviceInput. I've edited the question to correct the mistake – katewall Jul 27 '15 at 19:24
  • well, that was the only problem i saw. other than that, the rest looks good. Have u tried debugging it? – dudeman Jul 27 '15 at 20:06

0 Answers0