-4

誰でも次の方法の使用方法の例を教えてもらえますか:

 (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError
4

1 に答える 1

2

ここでAppleのリファレンスをチェックしてください: AVCaptureDevice

最初に AVFoundation をインポートし、ビルド フェーズに追加します。

#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!");
}
于 2012-10-29T20:10:46.130 に答える