Как предотвратить мигание приложения фонарика iPhone 4 при его выключении? - PullRequest
1 голос
/ 10 августа 2011

Я играю с небольшим простым фонариком, который включает и выключает светодиодную вспышку при нажатии кнопок на моем виде.

Работает просто отлично, но когда я выключаю вспышку, она мигает один раз перед выключением.Есть идеи, что вызывает такое поведение?

Вот соответствующий код:

//
//  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 уровня класса.

И да, это код, который я простонашел в интернете.Я просто играю и пытаюсь разобраться.

1 Ответ

0 голосов
/ 12 августа 2011

Я понял, что происходит, и это не имело никакого отношения к коду. :) Ошибка ID10T.

Я скопировал кнопку «Включить», чтобы создать кнопку «Выключить». Я забыл отключить соединение кнопки «Выключить» с методом TurnOnLight, который был там из-за копирования.

Я просто удалил это соединение, и теперь приложение работает отлично! :)

Извлеченный урок: иногда проблема заключается не в вашем исходном коде. : D

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...