Việc bật đèn flash của thiết bị trong phiên AR có thể giúp cải thiện khả năng hiển thị.
Kiểm tra để đảm bảo cấu hình máy ảnh hiện tại hỗ trợ đèn flash
Không phải cấu hình máy ảnh nào cũng hỗ trợ bật đèn flash. Trước khi bật đèn flash hoặc cho phép người dùng bật đèn flash, hãy đảm bảo rằng bạn có thể sử dụng đèn flash cho cấu hình máy ảnh đang hoạt động:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
return device.hasTorch;
}
return false;
Bật đèn flash
Bật đơn vị đèn flash bằng cách định cấu hình phiên AR bằng AVCaptureTorchModeOn
:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
if (device.hasTorch) {
NSError *error = nil;
if ([device lockForConfiguration:&error]) {
device.torchMode = AVCaptureTorchModeOn;
[device unlockForConfiguration];
} else {
return;
}
}
}
Tắt đèn flash
Tắt đơn vị đèn flash bằng cách định cấu hình phiên AR bằng AVCaptureTorchModeOff
:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (device) {
if (device.hasTorch) {
NSError *error = nil;
if ([device lockForConfiguration:&error]) {
device.torchMode = AVCaptureTorchModeOff;
[device unlockForConfiguration];
} else {
return;
}
}
}