I would like to know if it's possible to receive notification about autofocus inside an iPhone application?
I.E, does it exist a way to be notified when autofocus starts, ends, if it has succeed or failed... ?
If so, what is this notification name ?
Before you take a photo, the iPhone camera automatically sets the focus and exposure, and face detection balances the exposure across many faces. If you want to manually adjust the focus and exposure, do the following: Open Camera. Tap the screen to show the automatic focus area and exposure setting.
You can schedule a Focus to turn on at certain times, when you're at a particular location, or when you open a specific app. Go to Settings > Focus, then tap the Focus you want to schedule. at the top left. Tap Add Schedule, then set the times, a location, or an app you want to activate this Focus.
Your camera focuses and adjusts exposure automatically based on what you're pointing it towards. You can tap a different area in the viewfinder to change the focus and exposure. If you want to keep the focus and exposure in the same spot, press and hold on the screen until you see AE/AF Lock.
I find the solution for my case to find when autofocus starts / ends. It's simply dealing with KVO (Key-Value Observing).
In my UIViewController:
// callback
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if( [keyPath isEqualToString:@"adjustingFocus"] ){
BOOL adjustingFocus = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualToNumber:[NSNumber numberWithInt:1] ];
NSLog(@"Is adjusting focus? %@", adjustingFocus ? @"YES" : @"NO" );
NSLog(@"Change dictionary: %@", change);
}
}
// register observer
- (void)viewWillAppear:(BOOL)animated{
AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
int flags = NSKeyValueObservingOptionNew;
[camDevice addObserver:self forKeyPath:@"adjustingFocus" options:flags context:nil];
(...)
}
// unregister observer
- (void)viewWillDisappear:(BOOL)animated{
AVCaptureDevice *camDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[camDevice removeObserver:self forKeyPath:@"adjustingFocus"];
(...)
}
Documentation:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With