Camera (AVFoundation new APIs) classes for iOS 10 does not found - objective-c

I am facing the error: No known method for selector
defaultDeviceWithDeviceType:mediaType:position:
While documentation for this method is given at:
AVCap
When I call this method, it shows error that method not found. My code is:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithDeviceType: AVCaptureDeviceTypeBuiltInDuoCamera
mediaType: AVMediaTypeVideo
position: AVCaptureDevicePositionBack];
Here are all the version details:
MacOS: 10.11.5,
xCode: 8.0 beta,
iOS: 10.0.1

The AVCaptureDevice methods devices and devicesWithMediaType: are deprecated in iOS 10, and do not provide access to the dual camera or telephoto camera.
When you use the AVCaptureDevice class for video or photo capture, you
can choose to use the dual camera device to gain these features, or to
specifically use only the wide-angle or telephoto camera for more
manual control.
To access capture devices in iOS 10.0 and later, you can use either of the following methods:
Call the defaultDeviceWithDeviceType:mediaType:position: method. (Pass the AVCaptureDeviceTypeBuiltInDuoCamera device type to access the dual camera.
That call returns nil for devices without a dual camera—in that case, you can call the same method again, passing the AVCaptureDeviceTypeBuiltInWideAngleCamera device type, to obtain the default back camera.)
Create an AVCaptureDeviceDiscoverySession object, passing the device attributes you want to use for capture, and enumerate its devices list to select a device for your capture session.
read docs here:
https://developer.apple.com/library/content/releasenotes/General/WhatsNewIniOS/Articles/iOS10.html#//apple_ref/doc/uid/TP40017084-DontLinkElementID_11

When I switched from xCode 8.0 beta to release version xCode 8.0 then it worked.Thanks

Related

In OS X 10.9 (xcode 5.1), how to show local notification on top-right(menu bar) in my program?

Why local notification is no supported by OS X 10.9? I know IOS has UILocalNotification Class.
I want to show some notification bellow menu bar which is generated by my program.
Is there any alternate way to do this? Or should I write my own local notification view?
It sounds like you are looking for NSUserNotification functionality, which goes along with the MacOS NSUserNotificationCenter.
I've linked the documentation at Apple to help you out.
As you are learning, many classes and objects supplied in the iOS SDK don't have exact same classes and objects in the MacOS SDK. Anything with "UI" in the framework name is usually meant only for iOS.

AVAudioSessionCategoryPlayAndRecord makes AirPlay invisible

I am encountering the following problem: AirPlay becomes not available whenever I set play-and-record category to the audio session in my application:
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayAndRecord
error: &setCategoryError];
This call makes the AirPlay disappear and reroutes the audio to the speaker immediately.
The problem can be easily reproduced e.g. on the sample project avTouch from Xcode documentation by replacing AVAudioSessionCategoryPlayback category with AVAudioSessionCategoryPlayAndRecord: in the original example AirPlay picker is visible and allows to change output source, whereas with the AVAudioSessionCategoryPlayAndRecord category the picker disappears.
Is there a proper way to switch to AVAudioSessionCategoryPlayAndRecord category so that the AirPlay is still available?
(A question like this has been already asked, but didn't get any answer.)
What AirPlay device are you trying to use? Does it have a microphone?
If not, iOS won't present it as an option when using the PlayAndRecord category, because that device can't play and record. It would show up when using the Play category though.
Also, if the device you are using is a Bluetooth device, have you set AVAudioSessionCategoryOptionAllowBluetooth to YES?
I think you should add the code below above AVAudioSession. I hope it works.
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error: &setCategoryError];
if (setCategoryError) {
// Handle error
}
Well, AirPlay and the PlayAndRecord category are just incompatible.
That's what I learned from the Apple forums.
Why do you need audio input on the device when audio output happens somewhere else?

How do you programmatically detect your iPad's generation?

I'm working on a program that needs to be able to detect whether or not camera hardware is present in the iPad. I assumed that the easiest way to do this was to determine what generation the device was, but if there is a simpler way to detect the hardware that works too. The iPads that this application is being designed for will likely be recently purchased and running on a standard updated version of iOS.
Nope You can simply check what device is being used!
For checking all iOS devices:
NSString *deviceType = [UIDevice currentDevice].model;
NSLog(deviceType);
In order to check for a camera
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
//there is a camera

How do I exclude iPad 2 and iPod Touch 5th Generation in a function?

I'm trying to create a function that works on ALL iOS devices except the iPad 2 and the iPod Touch 5th Gen.
- (void)doSomething {
// if iPad 2 or iPod 5th Gen
if ()
{
NSLog(#"You're using an iPad 2 or iPod 5th Gen. Sorry!");
}
else
{
NSLog(#"Any other iOS device. Congrats!");
} }
Can someone post a quick sample snippet of how I would accomplish this?
If your app has a major hardware requirement (i.e., it can't really function/do anything useful if the hardware isn't present on the device), you should add an entry to the UIRequiredDeviceCapabilities entry in your Info.plist for your app. This will keep people who don't have the necessary hardware to use your app from purchasing it/downloading it by accident. It will also cause the App store to show a list of all the models that support your software, so people can see what they need in order to use it.
If your app has a function that requires something specific, there are generally in-framework tests you can do to see if the device has the required features/hardware. If this isn't your app's central purpose, you can then enable/disable this feature of your app based on the device's capabilities. You wouldn't want to try and query which device the user is running (except in maybe very limited circumstances), but would rather query whether the device is capable of doing what you want.
Since you mentioned an auto-focusing camera, we'll use that as an example. If your app requires this to do anything useful, you should add the UIRequiredDeviceCapabilities key to your Info.plist file and add the entry auto-focus-camera to the array. This will ensure that only users who have a device with an auto-focusing camera will be able to purchase and install your app. For more information on UIKit keys for Info.plist, including this one, see the Information Property List Key Reference.
If, on the other hand, your app is usable by any device but has a feature that requires an auto-focusing camera, you can test for it's presence using the AVFoundation framework. You can get what you need here from the AVCaptureDevice class. For example, to check if you have access to an auto-focusing camera for video/stills:
// Check for the default camera
AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if( camera && [camera isFocusModeSupported:AVCaptureFocusModeAutoFocus] ) {
// this device has a default video source capable of autofocus, so enable the feature
} else {
// this device does not have the required hardware, so disable the feature
}
Check this:
if ([[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
//device with autofocus
}
else {
//device without autofocus
}

iPhone checking for existence of AVCaptureSession Class

I have integrated a library that uses AVCaptureSession to capture a photo from the camera. As the AVCaptureSession is only available on iOS 4 devices, I want to disable this integrated functionality for older devices.
I know that it should be done by weak-linking the AVFoundation Framework and checking for function existence. Weak-linking is easy to do, but which function should I check for existence here? AVCaptureSession is a class and not a function.
Are there some sample code available?
I think you're looking for NSClassFromString:
Class NSClassFromString ( NSString *aClassName );
You can then guard usage of that class with something like this:
if (NSClassFromString(#"AVCaptureSession")) {
...
}