0

AVCaptureSession を使用してカメラ出力を表示する必要があります。私のコードは、iPhone 3G を除くすべてのデバイスで正常に動作します。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Receiving events
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didGetError:) name:AVCaptureSessionRuntimeErrorNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didStartRunning:) name:AVCaptureSessionDidStartRunningNotification object:nil];

    self.session = [[AVCaptureSession alloc] init];

    NSString *preset = AVCaptureSessionPresetLow;
    self.session.sessionPreset = preset;
    self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];
    [self.session addInput:self.input];

    // Setting up the preview layer. It causes the error.
    self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
    [self.view.layer addSublayer:self.previewLayer];
    self.previewLayer.frame = self.view.bounds;

    [self.session startRunning];
}


- (void)didStartRunning:(NSNotification *)notification 
{
    NSLog(@"started");
}


- (void)didGetError:(NSNotification *)notification 
{
    NSError *error = notification.userInfo[AVCaptureSessionErrorKey];
    NSLog(@"error: %@", error.localizedDescription);
}

出力は次
のとおりです。 エラー: 操作を完了できませんでし
た。

回避策を教えてもらえますか?Apple のAVCamの例は、3G でも機能しません。

4

0 に答える 0