Question

I've enabled the restrictions and disallowed the camera and FaceTime in the settings of iPad and in the privacy tab, I disabled the access to photos for my application.

I'm opening the camera and photo library using below code,

//For camera
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = NO;
[self.view.window.rootViewController presentViewController:picker animated:YES completion:nil];

//For Photo library
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[self.view.window.rootViewController presentViewController:picker animated:YES completion:nil];

While opening the photo library, it clearly displays a message that the access is denied and it can be changed in the settings app. But while opening camera, the app crashes throwing the error,

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available' *** First throw call stack: (0x30584f4b 0x3ac566af 0x32f56d69 0x1141d9 0x32ee4d03 0x32d2c713 0x32d2c6b3 0x32d2c691 0x32d1811f 0x32d2c107 0x32d2bdd9 0x32d26e65 0x32cfc79d 0x32cfafa3 0x30550183 0x3054f653 0x3054de47 0x304b8c27 0x304b8a0b 0x3518c283 0x32d5c049 0xeff7d 0x3b15eab7) libc++abi.dylib: terminating with uncaught exception of type NSException

How to fix this?

Was it helpful?

Solution

You should always check wether a source type is available:

From the Apple UIImagePickerController doucmentatiom

Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the UIImagePickerControllerSourceType enumeration.

Check wether the source is available like:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
 // UIImagePickerControllerSourceTypePhotoLibrary is available.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top