iPhone 5's low light boost mode - iphone

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).

Related

Switch On/Off flash while recording the Video in iphone app

I am recording video from my iPhone app.
I am using an overlay over the camera and placed a button in the overlay. I want to know with the help of which function can I turn camera's flash on/off while the video is being recorded.
How can I set a flash button in the camera overlay?
If you are using AVFoundation for video recording, You should first check if device has torch/flash because torch is available when video is being recorded from the back camera, you can not have the torch/flash when using front camera.
using something like this
- (BOOL) hasTorch
{
return [[[self avCaptureDeviceInput] device] hasTorch];
}
and then set the torch accordingly using AVCaptureTorchMode
- (void) setTorchMode:(AVCaptureTorchMode)torchMode
{
AVCaptureDevice *device = [[self videoInput] device];
if ([device isTorchModeSupported:torchMode] && [device torchMode] != torchMode) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setTorchMode:torchMode];
[device unlockForConfiguration];
} else {
id deleg = [self delegate];
if ([deleg respondsToSelector:#selector(acquiringDeviceLockFailedWithError:)]) {
[deleg acquiringDeviceLockFailedWithError:error];
}
}
}
}
if you follow the AVCam Demo from Apple you will get your answers basically.
Assuming you are using UIImagePickerController (from your tag), use the cameraFlashMode provided by UIImagePickerController to control the flash.
You can set its value to UIImagePickerControllerCameraFlashModeOff, UIImagePickerControllerCameraFlashModeAuto or UIImagePickerControllerCameraFlashModeOn. Default is auto.

What will happen to users running a lower version of IOS if new code is called?

I am fairly new to iOS Development and I've always wondered if a user running my application on iOS 4 were to try and run this code:
//POST TWEET//
- (void)showTweetSheet
{
TWTweetComposeViewController *tweetSheet =
[[TWTweetComposeViewController alloc] init];
tweetSheet.completionHandler = ^(TWTweetComposeViewControllerResult result) {
switch(result) {
case TWTweetComposeViewControllerResultCancelled:
break;
case TWTweetComposeViewControllerResultDone:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"Tweet Sheet has been dismissed.");
}];
});
};
[tweetSheet setInitialText:#"Check out this cool picture I found on #Pickr_"];
// Add an URL to the Tweet. You can add multiple URLs.
if (![tweetSheet addURL:[NSURL URLWithString:ImageHost]]){
NSLog(#"Unable to add the URL!");
}
[self presentViewController:tweetSheet animated:YES completion:^{
NSLog(#"Tweet sheet has been presented.");
}];
}
What would happen? Would the application just terminate with an error or will the code just not run? And how do I properly implement features that are OS specific? Would I just use something like this:
NSString *DeviceVersion = [[UIDevice currentDevice] systemVersion];
int DeviceVersionInt = [DeviceVersion intValue];
if (DeviceVersionInt > 5)
{
//do something.
}
else
{
//don't do a thing.
}
It will crash on iOS 4 if you write iOS5 features without checking if they are available or not. Try to implement Twitter like this
Class twClass = NSClassFromString(#"TWTweetComposeViewController");
if (!twClass) // Framework not available, older iOS
{
//use iOS4 SDK to implement Twitter framework
}
else {
//use Apple provided default Twitter framework
}
Make sure you have added Twitter Framework with weak link.
Id imagine that it would work the same as with any other api. If you link against a function which is not in a previous version, the program will crash on an attempt to call the function. Therefore, version switches are used, as you demonstrated, to avoid crashes.
The app would crash. If you want to implement features based on iOS, you can use a variety of methods. See this question.

Make an iPhone specific app work on iPad to meet Apple requirements

My app has been in the AppStore for a couple of months now and always only worked on iPhone. I recently submitted an update which was rejected because the App does not run on an iPad. The exact reason it was rejected was:
Reasons for Rejection:
2.10: iPhone apps must also run on iPad without modification, at iPhone resolution, and at 2X iPhone 3GS resolution
What do I need to do in Xcode to make my app run on an iPad in the little box with the 2X icon?
Any tips instructions will be massively appreciated...
EDIT
This is my info.plist. This is my first App and I think I did initially chose to set it up with "universal" selected. Is there an easy way back for me to rectify this now?
Start by figuring out why your app doesn't work on the iPad already. Most apps developed for the iPhone will work fine on an iPad (in compatibility mode) with no modification; if yours doesn't, you must be doing something to prevent it. Are you relying on some hardware feature? Making unfounded assumptions about the device you're running on? How does your app fail when run on an iPad?
Once you've figured out why it doesn't work, you'll be much closer than you are now to fixing the problem.
To get your app to run on an iPad in iPhone compatibility mode, you need to build your app for iPhone only.
Remove all the iPad references from the app's plist (nib base, xib and storyboard), and from the Target Build Settings Targeted Device Family.
I had the same issue, I was able to run my app on the ipad after making the following changes.
in the project settings made the Devices to iPhone(it was universal before)
in the .plist removed the main story board file base name related to ipad.
I have solved same issue using this scenario.
You should check for normal and retina images in your resources folder.
You may also get this error while debugging Could not load the "image.png" image referenced from a nib in the bundle with identifier.
A normal iPhone app must run on the iPad in both(1x and 2x) mode without modification. You can check this with the SDK Simulator.
There is a long list in the App Store Review Guidelines on Apple's iOS Developer Portal Center which lists many of the things that Apple reviews this things when you submit an app. Read it carefully.
I'll try to explain what my problem and solution was..
I have an iPhone only app which is mostly in portrait, however, because of 1 or 2 UIViewControllers which have to be in all UIInterfaceOrientations, I have to enable all UIInterfaceOrientations in my plist.
When starting the app on an iPad which is rotated in landscape and is lying on the table (so has UIDeviceOrientationFaceUp), the whole app was shown in landscape, which made my UI totally messed up.
I had no reference to any iPad related code / settings in my plist or launch screens whatsoever (I am using .xcassets for launch screens).
I fixed it by adding 1 line of code to my AppDelegate.m which sets the statusbar orientation to force the app in portrait mode.
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
//Further setup
}
I had the same issue using Cocos2d 2.0
My problem was that the project had evolved over several years and had carried along some now vestigial files like RootViewController and UIViewController and MyRootViewController, etc.
They worked at the time but clearly had raised a flag with today's review committee because I received the "All iPhone apps must work on the iPad" rejection notice. After screaming out loud and finally accepting defeat, I thought that policy makes it pretty hard to make an app iPhone only. Let me know if I am wrong about this.
Even though I was (and am still) perturbed about it, I thought perhaps now I could at least clean up the project with a more elegant solution that handles the base problem: device rotation + content rotation. I ended up using something from a more recent project that was working on and seemed more elegant and actually worked: simply add MyNavigationController to the top of my AppDelegate.
I have added the code below. I am sure it can be improved. Please comment if you can enhance it.
As a result, I was able to delete the old RootViewController and MyRootViewController files so now it's easier to maintain. I never understood their purpose very well anyways. Good riddance!
Here is my solution to displaying and matching device orientation + content orientation:
in AppDelegate.h I had to declare what I was doing:
//top of the file
#interface MyNavigationController : UINavigationController
#end
//inside AppDelegate.h interface
MyNavigationController *navController_;
//bottom of the file before #end
#property (readonly) MyNavigationController *navController;
Here is the code that works at the top of my AppDelegate.m
#implementation MyNavigationController
// The available orientations should be defined in the Info.plist file.
// And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method.
// Only valid for iOS 6+. NOT VALID for iOS 4 / 5.
-(NSUInteger)supportedInterfaceOrientations {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
} else if (orientation == UIDeviceOrientationLandscapeLeft) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationLandscapeRight) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// [director_ pushScene: [IPAD scene]];
} else {
[[CCDirectorIOS sharedDirector] pushScene:[MainMenuScene scene]];
}
} else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
} else {
//do nothing
}
return UIInterfaceOrientationMaskLandscape;
}
//this is the one for iOS 6
- (BOOL)shouldAutorotate {
//NSLog(#"MyNavigationController - should Rotate ToInterfaceOrientation ...");
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
// iPhone only
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ) {
//NSLog(#"MyNavigationController - should Rotate iPhone");
if (orientation == UIDeviceOrientationPortrait) {
//NSLog(#"should Rotate iPhone orientation is Portrait");
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortrait;
}
if (orientation == UIDeviceOrientationPortraitUpsideDown) {
//NSLog(#"should Rotate iPhone orientation is PortraitUpsideDown");
[[CCDirectorIOS sharedDirector] pushScene:[VerticalDisplayLayer scene]];
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
if (orientation == UIDeviceOrientationLandscapeLeft) {
//NSLog(#"should Rotate iPhone orientation is Landscape Left");
return UIInterfaceOrientationMaskLandscape;
}
if (orientation == UIDeviceOrientationLandscapeRight) {
//NSLog(#"should Rotate iPhone orientation is Landscape Right");
return UIInterfaceOrientationMaskLandscape;
}
return TRUE;
}
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad ) {
//NSLog(#"MyNavigationController - should Rotate iPad");
return TRUE;
}
return TRUE;
}
// Supported orientations. Customize it for your own needs
// Only valid on iOS 4 / 5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
// iPhone only
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
return TRUE;
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad )
return TRUE;
// iPad only
// iPhone only
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
return TRUE;
}
// This is needed for iOS4 and iOS5 in order to ensure
// that the 1st scene has the correct dimensions
// This is not needed on iOS6 and could be added to the application:didFinish...
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if(director.runningScene == nil) {
// Add the first scene to the stack. The director will draw it immediately into the framebuffer. (Animation is started automatically when the view is displayed.)
// and add the scene to the stack. The director will run it when it automatically when the view is displayed.
[director runWithScene: [MainMenuScene scene]];
}
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// Assuming that the main window has the size of the screen
// BUG: This won't work if the EAGLView is not fullscreen
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect = CGRectZero;
//NSLog(#"MyNavigationController - Will RotateToInterfaceOrientation ...");
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
rect = screenRect;
} else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
rect.size = CGSizeMake( screenRect.size.height, screenRect.size.width );
}
CCDirector *director = [CCDirector sharedDirector];
CCGLView *glView = (CCGLView *)[director view];
glView.frame = rect;
}
#end
Here is why I had to solve this:
I needed both Landscape and Portrait modes to display different scenes.
Here are some screenshots that describe the situation

how to know is it iphone or ipad?

i want to know the user uses the iphone or ipad,if the user uses the iphone i want to open the camera,if he uses the ipad or runs in simulator i want to open the library. how it is possible?
how to find the details of devices?
how to know current using device by user through xcode?
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:#"iPhone"])
{
//your code
}
.....
Hope this helps.
EDIT:
See this thread -determine-device-iphone-ipod-touch-with-iphone-sdk .
[[UIDevice currentDevice].model hasPrefix:#"iPhone"]
Use the "hasPrefix" so that it works in simulator.
You should not determine whether there is a camera by looking at the model. This is not future proof - for instance, you would not be supporting the iPad 2's camera.
UIImagePickerController has a special method to determine whether a camera in available:
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
With sourceType being one of
UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
Make use of this to identify devices.
// If iPhoneOS is 3.2 or greater then __IPHONE_3_2 will be defined
#ifndef __IPHONE_3_2
typedef enum {
UIUserInterfaceIdiomPhone, // iPhone and iPod touch
UIUserInterfaceIdiomPad, // iPad
} UIUserInterfaceIdiom;
#define UI_USER_INTERFACE_IDIOM() UIUserInterfaceIdiomPhone
#endif // ifndef __IPHONE_3_2
but if you want to check if camera is available I think you can make use of UIImagePickerController's static method
+ (BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType
Working on Vaibhav Tekam's answer, I used this
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType hasPrefix:#"iPhone"])
{
//your code
}
or
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType hasPrefix:#"iPad"])
{
//your code
}
etc.
It's much easier that way as it covers all models.

IPhone iOS 4.3 camera focus square - removeable programmatically?

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.