2012-10-29 68 views
-4

誰能告訴我如何使用下面的方法的例子:LED照明在iOS 6中

(BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError 
+2

堆棧溢出不是您的個人研究助理。請閱讀常見問題。 – 2012-10-29 20:02:45

回答

2

退房蘋果的參考這裏:AVCaptureDevice

首次進口AVFoundation和add it to the build phases.

#import <AVFoundation/AVFoundation.h> 

然後使用以下代碼:

//Get all devices (front and back camera) 
for (AVCaptureDevice *device in [AVCaptureDevice devices]) { 

    if ([device position] != AVCaptureDevicePositionBack) { 
     NSLog(@"This is the front camera"); 
     continue; // go to next device 
    } 

    NSLog(@"This is the back camera"); 

    if([device hasTorch] == NO){ 
     NSLog(@"this camera has no torch..."); 
     continue; // go to next device 
    } 

    NSLog(@"The camera has a torch"); 

    if([device isTorchAvailable] == NO){ 
     NSLog(@"The torch is not available..."); 
     continue; // go to next device 
    } 

    NSLog(@"The torch is available"); 

    //get device dependent maximum (between 0 and 1) 
    float level = AVCaptureMaxAvailableTorchLevel; 

    NSError* outError; 
    BOOL success = [device setTorchModeOnWithLevel:level error:&outError]; 

    if(!success){ 
     NSLog(@"Could not activate torch: %@", [outError localizedDescription]); 
     continue; // go to next device 
    } 

    NSLog(@"The torch is now active!"); 
}