Is it necessary to check if camera exists when targeting iOS 6+? - ios

I am making an app that makes use of the camera in multiple areas and it came upon me that all devices that support iOS 6+ have a camera. This is more of a programming practice question than a practical implementation question.
Apple never explicitly recommends that you have to check for a camera, but many developers do.
Is it safe to not check? What are the implications of NOT checking for a camera?
Is there any performance advantage/disadvantage?
Thanks,
Virindh Borra

From the docs for the UIImagePickerController isSourceTypeAvailable: method:
Because a media source may not be present or may be unavailable, devices may not always support all source types. For example, if you attempt to pick an image from the user’s library and the library is empty, this method returns NO. Similarly, if the camera is already in use, this method returns NO.
Before attempting to use an UIImagePickerController object to pick an image, you must call this method to ensure that the desired source type is available.
So yes Apple does tell you to check. Besides, how hard is it to do:
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
// show camera
} else {
// don't show camera
}

Related

Modifying iPhone Camera/Flashlight?

I was wondering if there's anyway to modify how the iPhone takes pictures. Specifically, if you can turn off the dimmer focus flash that shows up before the full flash, so when you take a picture it's just the full flashlight that comes on immediately. Thanks!
Unfortunately, no, I think not. From the apple developer site:
Flash Modes
There are three flash modes:
AVCaptureFlashModeOff: The flash will never fire.
AVCaptureFlashModeOn: The flash will always fire.
AVCaptureFlashModeAuto: The flash will fire dependent on the ambient
light conditions. You use hasFlash to determine whether a device has a
flash. If that method returns YES, you then use the
isFlashModeSupported: method, passing the desired mode to determine
whether a device supports a given flash mode, then set the mode using
the flashMode property.
And there is no mention of the dimmer flash.
EDIT: Maybe you can. There are lots of iOS apps that do this
2nd Edit: After looking at this, I have concluded that you cannot do so.

Track device orientation when orientation is locked

I need to track device orientation even though device orientation is locked to Portrait mode. What I really need is to accomplish similar behaviour to what Instagram camera view has: when you rotate device, it will rotate buttons over camera view, even when your device is locked.
I used to track orientation with UIDeviceOrientationDidChangeNotification, but that is not fired when device orientation is locked :(
Is there perhaps implementation somewhere using accelerometer and/or gyroscope? I'm suprised I couldn't find something like that.
Use the accelerometer to detect device orientation yourself. You can use the Core Motion framework to get the data you need. There's a sample snippet in the linked docs that shows how to get the data. Use a low-pass filter to isolate the force of gravity from relatively short-term changes due to user movement. Apple has a sample project called AccelerometerGraph that demonstrates this.

CoreMotion - way to determine if motion is disabled in iOS Settings?

On iOS 7 the user can choose disable device motion in Settings -> General -> Accessibility -> Reduce Motion.
I am creating a UI effect based on UITableView scrolling, so I am not using CMMotionManager or the CoreMotion framework to create any motion effects.
However, I would like to respect the user's settings and not create the motion effect if the user has turned on Reduce Motion in Settings.
CMMotionManager includes an instance method deviceMotionActive to check for whether it's active (I'm assuming this is the correct check), however, I'd prefer not having to initialize the manager just to do this check, sadly I cannot find any documentation about a class method that would return a similar boolean, sort of like there exist class methods on MFMessageComposeViewController to check for iMessage/SMS availability (+(BOOL)canSendText) and so on.
Thanks!
You are confusing two separate things called "motion". CMMotionManager is used to access the sensors, such as the gyroscope and accelerometer, that report how a user physically moves a device. It has nothing to do with the motion effects, like UIMotionEffect objects, that are used in animating views.
The deviceMotionActive method merely indicates whether your app is currently registered for receiving motion updates from CoreMotion. This will only be true if your app has called one of the CMMotionManager startXXXUpdate methods. Again, it has nothing to do with user settings or UIMotionEffect objects.
UPDATE: As John mentions in the comments, there appears to be an API for this in iOS 8: See stackoverflow.com/a/25453082/2904769 .

Automatically take a Picture

I have tried to take a picture and save it to the photo library automatically with UIImagePicker and AVFoundation, but I couldn't make it work.
I would like to take the photo when the view appears, not showing the camera view to the user, and then use it as a simple image in the app.
Thanks
Apple actually has an entire guide devoted to this sort of thing, "Camera Programming Topics for iOS," with a subsection "Taking Pictures and Movies." There's even a sample project, "Photo Picker." Here's an excerpt, the action method for your take-a-picture button:
- (IBAction)cameraAction:(id)sender {
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
Note: It won't work unless [UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] returns YES, indicating that the device has a camera.

What is the name of the method for screenshot on iOS

I was wondering if there was a specific method called when we press the 2 buttons of the iPhone (using Home-Button & Power on/off) to take a screenshot. If yes, I would known his name to use her in programming.
There used to be a UIGetScreenImage() function that you could use to capture the screen. Apple no longer allows use of that function in App Store apps, so you have a few other options. CALayer has a -renderInContext: method—Google it—that you can use to copy a view’s contents to a graphics context; this does not, however, work for OpenGL content, video, or live imagery from a device’s camera. I’m not sure about solutions for the first two, but for the latter—getting images from the camera—you’ll need to use the AVFoundation framework.
It is a system level service for which the app never receives any notification or method call.
I believe that would be a native method, not accessible from the IPhone SDK. In what context are you going to be using this? You might be looking for this - Take screenshot from code

Resources