预期“(”在AVCaptureSession之前

时间:2010-11-21 09:59:40

标签: iphone objective-c xcode camera

当我尝试构建我的应用程序时,XCode会向我显示此错误

预期“(”在AVCaptureSession之前

有人可以帮我修理这个警告吗?这是我的代码:

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];
            [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 ///
{
}

谢谢!

3 个答案:

答案 0 :(得分:1)

默认情况下,

UIViewController没有该方法。您没有该方法的实现,因此它会给您这个警告。如果您将尝试运行此代码 - 您将收到“未知选择器发送到实例”错误。

您必须在视图控制器中添加torchSession的属性或实现该特定方法。

答案 1 :(得分:1)

第一个答案不一定正确,因为您可能已经实现了该方法,但没有在头文件中声明它。

在您收到警告的行上,您将向self发送消息(在本例中为视图控制器)以使用参数CaptureSession

运行方法setTorchSession

如果您已在.m文件中实现了setTorchSessin方法,那么您只需在您的界面(.h文件)中通过在SwitchON_Flash方法下添加以下行来声明它:

- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureDeviceSession*)captureSession;

如果你的实现文件中没有这个方法,那么你的应用程序会因“发送到实例的无法识别的选择器”消息而崩溃。

答案 2 :(得分:0)

你确定这个类是AVCaptureDeviceSession吗?我根本无法在XCode帮助中找到它。

也许你的意思是AVCaptureSession