The application that i am working on runs on both iPhone & iPad . One of the functionality that the application has, is to capture image from camera. I am using UIImageP
Replace your code with this:
Swift 3
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera)
{
let imagePicker:UIImagePickerController = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
else
{
let alert:UIAlertController = UIAlertController(title: "Camera not available", message: "Unable to find a camera on this device", preferredStyle: UIAlertControllerStyle.alert)
self.present(alert, animated: true, completion: nil)
}
Swift 2
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)
{
let imagePicker:UIImagePickerController = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.allowsEditing = true
self.presentViewController(imagePicker, animated: true, completion: nil)
}
else
{
let alert:UIAlertController = UIAlertController(title: "Camera not available", message: "Unable to find a camera on this device", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alert, animated: true, completion: nil)
}
You should check camera is available or not:
if UIImagePickerController.isSourceTypeAvailable(.camera) {
// Implement UIImagePickerController
} else {
// Show error message
}
Here's how you can set an environmental variable: https://stackoverflow.com/a/31874419/3724800
And here's the code I use to open the camera in a Universal app:
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .camera;
imagePicker.allowsEditing = false
present(imagePicker, animated: true, completion: nil)
}
Finally I solved the problem,
I implement a Theme approach for all application. In my AppDelegate file i set user interface settings while the application is being initialize.
Here is the issue,
There is a UISlider in camera UI, this slider view is always visible in iPad rear camera but in iPhones it is only visible when your are using zoom.
UISlider.appearance().minimumTrackTintColor = themeUI.PrimaryColor.withAlphaComponent(100)
UISlider.appearance().thumbTintColor = themeUI.PrimaryColor
These two lines changes appearance for all the sliders in the application, which means it also changes the UI for camera slider.
As you can see at the screen shot that i granted, while drawing camera CoreGraphics library calls
[UISlider setMinimumTrackTintColor];
Somehow setting minimumTrackTintColor for slider is causing invalid context error.
Additionally setting thumTintColor works fine, it is also changing the thumb color for UISlider in Camera :)
Maybe this issue is related with Swift 3, I will report a bug and we will see :)