From Apple docs:
@property(nonatomic) AVCaptureFlashMode flashMode
Discussion
Before changing the value of this property,
you must call lockForConfiguration:
to acquire exclusive access to the device’s configuration properties.
Otherwise, setting the value of this property raises an exception.
When you are done configuring the device, call unlockForConfiguration
to release the lock and allow other devices to configure the settings.
That's why it's crashing, you need to acquire exclusive access.
So just add:
if ([device isFlashModeSupported:AVCaptureFlashModeOff) {
NSError *error;
if ([device lockForConfiguration:&error) {
//It's now safe to add your original code here....
[device setFlashMode:AVCaptureFlashModeOff];
}
else
NSLog(@"ERROR: %@", [error localizedDescription]);
}
This way if there is a reason why the app can't lock in the flash mode you want you will get an error. It will also skip over it so it won't raise and exception & crash.
*untested just from reading the docs.