When I try to build my application XCode shows me this error
Expected "(" before AVCaptureSession
Can someone help me fixing this warning? Here's my code:
ViewController.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
{
}
- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureSession *)CaptureSession;
@end
ViewController.m
#import "ViewController.h"
@implementation ViewController
UIAlertView *NoFlash;
- (IBAction)SwitchON_Flash
{
AVCaptureDevice *Device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([Device hasTorch] && [Device hasFlash])
{
if (Device.torchMode == AVCaptureTorchModeOff)
{
AVCaptureDevice *Device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *FlashInput = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
AVCaptureVideoDataOutput *VideoOutput = [[AVCaptureVideoDataOutput alloc] init];
AVCaptureSession *CaptureSession = [[AVCaptureSession alloc] init];
[CaptureSession beginConfiguration];
[CaptureSession addInput:FlashInput];
[CaptureSession addOutput:VideoOutput];
[CaptureSession commitConfiguration];
[CaptureSession startRunning];
[Device lockForConfiguration:nil];
[Device setTorchMode:AVCaptureTorchModeOn];
开发者_StackOverflow社区[Device setFlashMode:AVCaptureFlashModeOn];
[Device unlockForConfiguration];
[self setTorchSession:CaptureSession];
[CaptureSession release];
[VideoOutput release];
}
else
{
[torchSession stopRunning];
}
}
else
{
NoFlash = [[UIAlertView alloc] initWithTitle:@"Uh-Oh"
message:@"Your device doesn't have a flash camera"
delegate:nil
cancelButtonTitle:@"mhmm, OK"
otherButtonTitles:nil];
NoFlash.delegate = self;
[NoFlash show];
[NoFlash release];
}
}
- (void)setTorchSession:(AVCaptureSession *)CaptureSession <== /// ERROR HERE ///
{
}
Thanks!
UIViewController
does not have that method by default. You don't have the implementation of that method, hence it's giving you this warning. If you will try to run this code - you will get "unknown selector sent to instance" error.
You either have to add property for torchSession
in view controller or implement that specific method.
The first answer is not necessarily right as you may have implemented the method but simply not declared it in your header file.
On the line where you get the warning, you are sending a message to self (in this case your view controller) to run the method setTorchSession with the parameter CaptureSession
Provided you have implemented the setTorchSessin method in your .m file, all you have to do is declare it in your interface (.h file) by adding the following line under your SwitchON_Flash method:
- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureDeviceSession*)captureSession;
If you haven't got the method in your implementation file your App will crash with a "Unrecognised selector sent to instance" message.
Are you sure the class is AVCaptureDeviceSession ? I can't find it in XCode help at all.
Maybe you meant AVCaptureSession
精彩评论