I don't know why, but the below code worked for me.
void TurnFlashOn_platform(bool turnOn) {
AVCaptureDevice* device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]){
[device lockForConfiguration:nil]; //you must lock before setting torch mode
[device setTorchMode:turnOn ? AVCaptureTorchModeOn : AVCaptureTorchModeOff];
[device unlockForConfiguration];
}
}
I guess must be some typos. Thanks anyways.