ORStudios
ORStudios

Reputation: 3233

How to determine if a camera resolution is available in IOS?

I have a function that allows the user to activate the camera. Now I want to give that user the option to select their chosen resolution. The problem is before I offer them the resolution how do I check to see if it is available.

UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.mediaTypes =  [NSArray arrayWithObject:(NSString *)kUTTypeMovie];

/// Different Options If Avalaible
cameraUI.videoQuality = UIImagePickerControllerQualityType640x480;
cameraUI.videoQuality = UIImagePickerControllerQualityTypeIFrame960x540;
cameraUI.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;

Upvotes: 1

Views: 459

Answers (1)

Shams Ahmed
Shams Ahmed

Reputation: 4513

I don't believe there a defined method to determine this behavior as of yet in the iOS SDK...

Two alternatives are using existing keys or using a conditional statement that checks current device.

First alternative: using the existing UIImagePickerControllerQualityTypeHigh, UIImagePickerControllerQualityTypeMedium and UIImagePickerControllerQualityTypeLow you can specify the quality without knowing exactly what it is. This allows the users to always have the best option were available

Second alternative: using conditional statement to check current device version and compare that to a hard-cored list of device with there camera resolution

#include <sys/types.h>
#include <sys/sysctl.h>

- (NSString *) currentPlatform { // get current device
    size_t size;
    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    char *machine = malloc(size);
    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    NSString *platform = [NSString stringWithUTF8String:machine];
    free(machine);

    return platform;
}

// conditional statement 
NSString *device = [self currentPlatform];

if (device isEqualToString@"iPhone6,2") { // iPhone 5s 
    // return quality...
    // best bet is to look on Apple device spec and Wiki for deivce camera resolutions supported

}

For a full list of devices see this glist

Upvotes: 1

Related Questions