Iphone – Detecting when camera’s iris is open on iPhone

cameraiphone

For a cutom camera overlay I need to find out, when the iris is opened, because my overlay will allways shown while the iris is close (and then animating to open).

Any ideas ?

Best Solution

You can listen for the PLCameraViewIrisAnimationDidEndNotification notification. Since this is not officially documented, you might be in violation of the Apple TOS, but I think so long as you write your code so that it's defensive against the possibility that the name or contract of this notification might change (so in the future you might not get the event) you'll probably be ok. In other words, use a timer or other technique to ensure that the thing you want done when the iris is open will definitely happen eventually even if you never get the notification...

Trivial example without the defensive programming. (Of course, you can register an interest only for this specific notification as well, see the docs for the notification center.)

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(notificationCallback:)
                                             name:nil
                                           object:nil
 ];

- (void) notificationCallback:(NSNotification *) notification {
     if ([[notification name] isEqualToString:@"PLCameraViewIrisAnimationDidEndNotification"]) {
         NSLog(@"Iris open");
         // we don't need to listen any more
         [[NSNotificationCenter defaultCenter] removeObserver:self];
     }
}
Related Question