2011-08-10 3 views
1

내보기의 버튼을 누를 때 LED 플래시를 켜고 끄는 간단한 작은 손전등 앱으로 놀고 있습니다.iPhone 4 손전등 앱이 꺼져도 깜박 거리지 않게하려면 어떻게합니까?

정상적으로 작동하지만 플래시를 끄면 전원이 꺼지기 전에 한 번 깜박입니다. 이 문제의 원인은 무엇입니까?

다음은 관련 코드입니다 :

// 
// No_Frills_FlashlightViewController.m 
// No Frills Flashlight 
// 
// Created by Terry Donaghe on 8/9/11. 
// Copyright 2011 Tilde Projects. All rights reserved. 
// 

#import "No_Frills_FlashlightViewController.h" 

@implementation No_Frills_FlashlightViewController 

@synthesize AVSession; 


- (void)didReceiveMemoryWarning 
{ 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
} 
*/ 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (IBAction)TurnOnLight:(id)sender { 
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 

    AVSession = [[AVCaptureSession alloc] init]; 

    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil]; 
    [AVSession addInput:input]; 

    AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init]; 
    [AVSession addOutput:output]; 

    [AVSession beginConfiguration]; 
    [device lockForConfiguration:nil]; 

    [device setTorchMode:AVCaptureTorchModeOn]; 
    [device setFlashMode:AVCaptureFlashModeOn]; 

    [device unlockForConfiguration]; 
    [AVSession commitConfiguration]; 

    [AVSession startRunning]; 

    [self setAVSession:AVSession];  

    [output release]; 
} 

- (IBAction)TurnOffLight:(id)sender { 

    [AVSession stopRunning]; 
    [AVSession release]; 
    AVSession = nil; 
} 

- (IBAction)DoNothing:(id)sender { 
} 
@end 

AVSession 그냥 클래스 수준의 AVCaptureSession 변수입니다.

예, 이것은 인터넷에서 방금 찾은 코드입니다. 나는 단지 놀고 있고, 물건을 계산하려고 노력하고있다.

+0

함수에서 불빛을 끄고 플래시의 동작을 목격하는 각 줄에 중단 점을 추가하십시오. 이렇게하면 어떤 선이 문제를 일으키는 지 알 수 있습니다. –

+0

흥미 롭습니다. 중단 점 (메서드의 첫 번째 줄에 있음)에 도달하기 전에 꺼짐 버튼을 터치하자마자 깜박입니다. –

+0

은 TurnOffLight가 실행 된 직후에 실행되는 TurnOffLight 메서드입니까, 완전히 분리되어 있습니까? –

답변

0

나는 무슨 일이 일어나고 있는지 알았고 코드와는 아무런 관계가 없었다. :) ID10T 오류가 발생했습니다.

"켜기"버튼을 복사하여 "끄기"버튼을 만들었습니다. 복사로 인해 거기에 있던 TurnOnLight 메소드에 대한 "Turn Off"버튼의 연결을 끊는 것을 잊었습니다.

단순히 연결을 제거 했으므로 앱이 완벽하게 작동합니다. :)

강의 학습 : 때로는 소스 코드가 문제가되지 않습니다. : D

관련 문제