I'm confused!
I'm trying to manually adjust the exposure to fit the CGPoint in the center of the preview. I'm taking the device object and using setExposureMode and setExposurePointOfInterest in order to do the manipulation. The first thing I do is check to see if exposure mode is supported by the device. If not supported then return. If it is supported then set the values. My confusion is stemming from the fact that the value for device isExposureModeSupported:exposureMode returns NO. But it is supported! I have an iPhone 5c. If I ignore the return statement I do not receive any errors.
- (void)device:(AVCaptureDevice *)device exposureMode:(AVCaptureExposureMode)exposureMode atPoint:(CGPoint)point
{
BOOL exposureModeSupported = [device isExposureModeSupported:exposureMode];
if (!exposureModeSupported)
return;
if ([device lockForConfiguration:&error]) {
[device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[device setExposurePointOfInterest:point];
CALayer *exposeRect = [CALayer layer];
exposeRect.frame = CGRectMake(self.center.x-30, self.center.y-30, 60, 60);
exposeRect.borderColor = [UIColor whiteColor].CGColor;
exposeRect.borderWidth = 2;
exposeRect.name = #"exposeRect";
[self.previewLayer addSublayer:exposeRect];
[NSTimer scheduledTimerWithTimeInterval: 1
target: self
selector: #selector(dismissExposeRect)
userInfo: nil
repeats: NO];
[device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
[device unlockForConfiguration];
}
}
How can I check if exposure mode is supported if I can't trust the value returned?
I ended up AND-ing the check, but I'm not sure this is the correct way to check. The condition now looks like this:
if (![device isExposurePointOfInterestSupported] && ![device isExposureModeSupported:exposureMode])
return;
Has anyone else come across this and does anyone know how to properly handle this?
Thank you in advance.
Yes, you should check for exposurePointOfInterestSupported AND isExposureModeSupported:.
In your case, you are checking if the AVCaptureExposureMode given as an argument in your function is supported, but set the exposure to AVCaptureExposureModeContinuousAutoExposure, which is not necessarily supported.
I guess nobody wanted to chime in on this one. I ended up AND-ing the check, but I'm not sure this is the correct way to check but it worked.
Related
This question appears to be asked and answered many times but with no specific or accurate answer. Hence I will reframe the question for iOS7 and hope for some help.
I need to use AudioServicesPlaySystemSound to play sounds as timing is critical and this is only way to play simultaneous sound effect accurately with variable timing (try every other option).
This works well but I would like to adjust the volume. The only way it appears to be able to do this is with the buttons although some say use MPVolumeView (only works for music), some say use MPMusicPlayerController (but this also only works for music and is now depreciated), and others just say it cannot be done - which is looking more likely.
However, with iOS7 there is a slide control in settings>sounds for the ringer alert volume. Is there any way I can subclass, replicate, or access this slide control to change this volume from within the app?
Apple recommends using MPVolumeView, so I came up with this:
Add volumeSlider property:
#property (nonatomic, strong) UISlider *volumeSlider;
Init MPVolumeView and add somewhere to your view (can be hidden, without frame, or empty because of showsRouteButton = NO and showsVolumeSlider = NO):
MPVolumeView *volumeView = [MPVolumeView new];
volumeView.showsRouteButton = NO;
volumeView.showsVolumeSlider = NO;
[self.view addSubview:volumeView];
Find and save reference to UISlider:
__weak __typeof(self)weakSelf = self;
[[volumeView subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[UISlider class]]) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf.volumeSlider = obj;
*stop = YES;
}
}];
Add target action for UIControlEventValueChanged:
[self.volumeSlider addTarget:self action:#selector(handleVolumeChanged:) forControlEvents:UIControlEventValueChanged];
And then update your custom control when the volume has been changed (i.e. by the hardware volume controls):
- (void)handleVolumeChanged:(id)sender
{
NSLog(#"%s - %f", __PRETTY_FUNCTION__, self.volumeSlider.value);
self.myCustomVolumeSliderView.value = self.volumeSlider.value;
}
and also other way around:
- (IBAction)myCustomVolumeSliderViewValueChanged:(id)sender {
NSLog(#"set volume to: %f", self.myCustomVolumeSliderView.value);
self.volumeSlider.value = self.myCustomVolumeSliderView.value;
}
NOTE: Make sure that setting the self.volumeSlider.value doesn't loop back to setting self.myCustomVolumeSliderView.value.
Hope this helps someone (and that Apple doesn't remove MPVolumeSlider from MPVolumeView).
I think you want to control your volume through program
- (void)setVolume:(float)Level
{
OSStatus errorMsg = AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, Level);
if (errorMsg) {
NSLog(#"AudioQueueSetParameter returned %d when setting the volume.", errorMsg);
}
}
use this code to set volume level passing from your code by which button you want to control.
This question already has answers here:
Detecting Color of iPhone/iPad/iPod touch?
(6 answers)
Closed 9 years ago.
After iPhone 5c announcement, i'm curious if anybody knows an API how to get an iPhone 5c colour? I'm sure everyone will find it convenient loading a corresponding UI colour scheme to the device colour.
I'm thinking about wrapping it in something like the UIDevice category, which will return a UIColor.
Update:
#ColinE and #Ortwin Gentz
has indicated the availability of private UIDevice instance method calls for it.
Please note, that in case of iPhone 5c, what you are really looking for is deviceEnclosureColor, as deviceColor will always return #3b3b3c, as it is a front colour.
method signature:
-(id)_deviceInfoForKey:(struct __CFString { }*)arg1
UIDevice category for it:
#interface UIDevice (deviceColour)
- (id)_deviceInfoForKey:(struct __CFString { }*)arg1;
- (NSString*)deviceColourString_UntilAppleMakesItPublic;
- (NSString*)deviceEnclosureColour_UntilAppleMakesItPublic;
#end
#implementation UIDevice (deviceColour)
- (NSString*)deviceColourString_UntilAppleMakesItPublic
{
return [self _deviceInfoForKey:#"DeviceColor"];
}
- (NSString*)deviceEnclosureColour_UntilAppleMakesItPublic
{
return [self _deviceInfoForKey:#"DeviceEnclosureColor"];
}
#end
The device colour (used to?) be encoded in the serial number of the device. I don't have a device to test on with them not officially released yet, but I imagine the solution will be similar to this:
Typical format of the iPhone SN is as follows: AABCCDDDEEF
AA = Factory and Machine ID B = Year of Manufacturing (9 is
2009/2019, 0 is 2010/2020, 1 is 2011 and so on) CC = Production
Week (01 is week 1 of B, 11 is week 11 of B and so on) DDD =
Unique Identifier EE = Color (A4=black) F = size (S=16GB,
T=32GB)
[Source]
There is more information on old techniques here
I would like to point out however, that I expect there isn't a supported method of getting the serial number. Assuming you'd only like to know this information so that you can customise your UI, I'd just put in a user option or ask them to select the colour of their device on first startup (or some other early point in the app-user life)
There's a private API to retrieve both the DeviceColor and the DeviceEnclosureColor. In case of the iPhone 5c, the interesting part is the enclosure color (the device color = front color is always #3b3b3c).
UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString(#"deviceInfoForKey:");
if (![device respondsToSelector:selector]) {
selector = NSSelectorFromString(#"_deviceInfoForKey:");
}
if ([device respondsToSelector:selector]) {
NSLog(#"DeviceColor: %# DeviceEnclosureColor: %#", [device performSelector:selector withObject:#"DeviceColor"], [device performSelector:selector withObject:#"DeviceEnclosureColor"]);
}
I've blogged about this and provide a sample app:
http://www.futuretap.com/blog/device-colors/
Warning: As mentioned, this is a private API. Don't use this in App Store builds.
A number of people on Twitter have cited the following method:
[[UIDevice currentDevice] _deviceInfoForKey:#"DeviceColor"]
Although I have not confirmed it myself.
This may help you...
UIDevice *device = [UIDevice currentDevice];
SEL selector = NSSelectorFromString([device.systemVersion hasPrefix:#"7"] ? #"_deviceInfoForKey:" : #"deviceInfoForKey:");
if ([device respondsToSelector:selector]) {
NSLog(#"DeviceColor: %# DeviceEnclosureColor: %#",
[device performSelector:selector withObject:#"DeviceColor"],
[device performSelector:selector withObject:#"DeviceEnclosureColor"]);
}
Ref: Detecting Color of iPhone/iPad/iPod touch?
Has anyone been able to get the iPhone 5's new low light boost mode to work in their custom camera app? I tried the following code, but noticed no difference - whereas the native camera app significantly boosted the brightness.
if ([[captureManager backFacingCamera] isLowLightBoostEnabled]) {
[[captureManager backFacingCamera] automaticallyEnablesLowLightBoostWhenAvailable];
}
You need to lockForConfiguration, according to the docs (well, the header file):
if ([[self backFacingCamera] respondsToSelector:#selector(isLowLightBoostSupported)]) {
if ([[self backFacingCamera] lockForConfiguration:nil]) {
if ([self backFacingCamera].isLowLightBoostSupported)
[self backFacingCamera].automaticallyEnablesLowLightBoostWhenAvailable = YES;
[[self backFacingCamera] unlockForConfiguration];
}
}
Also, isLowLightBoostEnabled tells you whether or not the low light is actually being boosted, not whether it can be. That's the isLowLightBoostSupported selector, as above (to which only iOS 6 devices respond).
Since my friend updated his iPhone iOS to 4.3 there's a small square which appears every time he takes a picture with the camera.
We're developing an app that uses the camera and would like to remove this annoying square. I didn't find anything about it in Apple's UIImagePickerController documentation.
The square didn't exist in former iOS versions.
You may want to try to lock the focus to disable auto-focus. Here is a sample code:
NSArray *devices = [AVCaptureDevice devices];
NSError *error;
for (AVCaptureDevice *device in devices) {
if (([device hasMediaType:AVMediaTypeVideo]) &&
([device position] == AVCaptureDevicePositionBack) ) {
[device lockForConfiguration:&error];
if ([device isFocusModeSupported:AVCaptureFocusModeLocked]) {
device.focusMode = AVCaptureFocusModeLocked;
NSLog(#"Focus locked");
}
[device unlockForConfiguration];
}
}
Setting the .showsCameraControls property of your picker controller to NO should remove the focus square (it did pre 4.3, I don't think anything has changed), but the downside is you'll need to provide your own controls (to take photos, etc). It's all or nothing I'm afraid!
Create a custom overlay and default overlay will not display. You can make your overlay can be completely empty.
I am trying hard to emulate the basic functionality of the built in camera app. Thus far I have become stuck on the 'tap to focus' feature.
I have a UIView from which I am collecting UITouch events when a single finger is tapped on the UIView. This following method is called but the camera focus & the exposure are unchanged.
-(void)handleFocus:(UITouch*)touch
{
if( [camera lockForConfiguration:nil] )
{
CGPoint location = [touch locationInView:cameraView];
if( [camera isFocusPointOfInterestSupported] )
camera.focusPointOfInterest = location;
if( [camera isExposurePointOfInterestSupported] )
camera.exposurePointOfInterest = location;
[camera unlockForConfiguration];
[cameraView animFocus:location];
}
}
'camera' is my AVCaptureDevice & it is non-nil. Can someone perhaps tell me where I am going wrong?
Clues & boos all welcome.
M.
This snippet might help you...There is a CamDemo provided by apple floating around which allows you to focus, change exposure while tapping, set flash, swap cameras and more, it emulates the camera app pretty well, not sure if youll be able to find it since it was part of wwdc, but if u leave some email address in the comments i can email you the sample code...
- (void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
id delegate = [self delegate];
if ([delegate respondsToSelector:#selector(acquiringDeviceLockFailedWithError:)]) {
[delegate acquiringDeviceLockFailedWithError:error];
}
}
}
}