激活手电筒应用程序的LED [英] Activate the LED for a flashlight app

查看:123
本文介绍了激活手电筒应用程序的LED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的iPhone制作手电筒应用程式。我有一个iPhone 4,并希望利用我的iPhone上的LED我的项目。

I'm trying to make a flashlight app for my iPhone. I have an iPhone 4 and would like to utilize the LED on my iPhone for my project. Can anyone help me to get started with that?

推荐答案

使用以下命令:

AVCaptureSession * session = [[AVCaptureSession alloc] init];

[session beginConfiguration];

AVCaptureDevice * device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

if ([device hasTorch] && [device hasFlash]){
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];
[device setFlashMode:AVCaptureFlashModeOn]; 
[device unlockForConfiguration];

AVCaptureDeviceInput * flashInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
if (flashInput){
    [session addInput:flashInput];
}
    AVCaptureVideoDataOutput * output = [[AVCaptureVideoDataOutput alloc] init];
    [session addOutput:output];
        [output release];
    [session commitConfiguration];  
    [session startRunning];
}
[self setTorchSession:session];
[session release];

(从关于iPhoneDevSDK的讨论

这篇关于激活手电筒应用程序的LED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆