Uiimagepicker For showing camera - iphone-sdk-3.0

Hi everyone I am trying to make a camera app. I am doing this as
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
where picker is the object of UIimagepicker Controller.
But when is run the code then the application terminates showing the error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'
I am using this on simulator. I know that it is not possible to check camera in simulator, but we can test for that. I think it might be that because camera is not available thats why it's terminating.
But I saw an application with the same code but that was running on the simulator, just showing the camera view.
Just help me out how to resolve this problem. And moreover how can I put my custom view to the camera in that app?

You need to check if the device has camera available before setting the sourcetype.
The following can check if device has camera available.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
}
You can't check the camera functionality from your simulator. You can assign UIImagePickerControllerSourceTypePhotoLibrary as the sourceType to test on simulator.

Swift 2.2
if UIImagePickerController.isSourceTypeAvailable(.Camera) {
imagePicker.delegate = self
imagePicker.sourceType = .Camera
presentViewController(imagePicker, animated: true, completion: nil)
} else {
print("The device has no camera")
}
Saved photos album
if UIImagePickerController.isSourceTypeAvailable(.SavedPhotosAlbum) {
imagePicker.delegate = self
imagePicker.sourceType = .SavedPhotosAlbum
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}

Put Below Code Where Exception Occures. Remember You Need To Implement navigationController
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertController *alertView = [UIAlertController alertControllerWithTitle:#"ERROR" message:#"No Camera Avalible" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *ok = [UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
[self dismissViewControllerAnimated:alertView completion:nil];
}];
[alertView addAction:ok];
[self.navigationController presentViewController:alertView animated:YES completion:nil];
}

Related

App crashes RGBA in iOS 11 working fine in iOS10 and below

While I am opening image picker and selecting Gallery in that the app crashes in iOS 11 but it is working fine in iOS 10 and below
018-02-22 14:42:53.630334+0530[589:98531] * Assertion failure in -[UICGColor encodeWithCoder:],
2018-02-22 14:42:53.631850+0530[589:98531] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation.'
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:#"Choose From" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:#"Gallery" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
UIImagePickerController *imgpicker = [[UIImagePickerController alloc] init];
imgpicker.allowsEditing = YES;
imgpicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imgpicker.delegate=(id)self;
[self presentViewController:imgpicker animated:YES completion:nil];
}]];
This is not because of image picker and all.
This is just because of UITabbar I have assigned a background image for Tabbar. I just removed that it works fine now.

Double tap outside action sheet popover presented using UIAlertController leads to going back to parent view in ios8 xcode 6 beta 5

I have a action sheet which i am presenting using UIAlertcontroller in ios8 (xcode 6 beta 5).
I am using UIAlertcontroller because UIActionsheet ( which is deprecated in iOS 8 ) was not working properly in ios8, on click of any option in the actionsheet leaded me back to the parent view.
Now I am facing one issue in UIAlertcontroller too, double tap outside the action sheet popover is leading me back to the previous parent view.
Following is my code snippet:
UIAlertController *actionSheetIos8;
actionSheetIos8 = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
NSArray *buttonsArray = [self returnMoreArray];
int startY = 10;
for (int i = 0; i < [buttonsArray count]; i++) {
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:[buttonsArray objectAtIndex:i] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSString *newStr = [buttonsArray objectAtIndex:i];
newStr = [[newStr lowercaseString] stringByReplacingOccurrencesOfString:#" " withString:#"_"];
}];
[actionSheetIos8 addAction:defaultAction];
}
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
}];
[actionSheetIos8 setModalPresentationStyle:UIModalPresentationPopover];
UIPopoverPresentationController *popPresenter = [actionSheetIos8
popoverPresentationController];
popPresenter.sourceView = sender;
popPresenter.sourceRect = [sender frame];
dispatch_async(dispatch_get_main_queue(), ^ {
[self presentViewController:actionSheetIos8 animated:YES completion:nil];
});
The following solution worked for me in my popover presentation controller scenario; I suspect the same bug underlies your situation:
Set a delegate (conforms to UIPopoverPresentationControllerDelegate protocol) on your UIPopoverPresentationController.
Implement the delegate method popoverPresentationControllerShouldDismissPopover:.
For example:
/**
The presence of this delegate callback inhibits the popover presentation controller
from mistakenly calling 'dismissViewControllerAnimated:completion:' on us twice.
*/
- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController;
{
NSLog(#"delegate method called asking permission to dismiss popover");
return YES;
}
Here's more context, where I'm setting up my popover presentation controller with a presented controller and a delegate:
// Set modal presentation style and issue the presentViewController:animated:completion:
// call before retrieving popover presentation controller created for us, as suggested
// in the API documentation that is more recent than the sample code from the
// WWDC2014 slides in Session 228:
presentedController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:presentedController animated:YES completion:nil];
// Now we can retrieve the popover presentation controller and configure it:
UIPopoverPresentationController *popPC = presentedController.popoverPresentationController;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
CGRect popoverRect = cell.infoButton.bounds; // Assume 'cell' exists; it's an object of mine with an 'infoButton' view.
popPC.sourceView = cell.infoButton; // has to be provided along with sourceRect
popPC.sourceRect = popoverRect; // has to be provided along with sourceView
popPC.delegate = self; // or whomever you set to be your popover presentation controller delegate.

iOS 7 - Black preview screen in UIImagePickerController

Using the below code to launch the image picker to capture the image. Can any one help out to close this issue...
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if (self.camera)
{
self.camera = nil;
}
self.camera = [[UIImagePickerController alloc] init];
self.camera.sourceType = UIImagePickerControllerSourceTypeCamera;
self.camera.allowsEditing = NO;
self.camera.delegate = self;
[self presentViewController:self.camera animated:YES completion:NULL];
}
Before launching the UIImagePickerController if you have any GCD in background might be a reason for this issue. In my code have GCD before launching the UIImagePickerController, now removed the GCD it's working fine.

UIImagepickerController is not showing camera in full view for iPhone 4.2

When I invoke camera using the UIimagepicker controller it does not show in full screen mode on iPhone with iOS version 4.2, but it does work in iOS 5.
Can anyone tell me the code that needs to be changed and what is the problem with existing code?
I am using the following code:
- (IBAction)takePicture:(id)sender
{
UIImagePickerController* imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = YES;
imagePicker.allowsEditing = NO;
imagePicker.toolbarHidden = YES;
imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
imagePicker.wantsFullScreenLayout = YES;
if ([UIImagePickerController respondsToSelector:#selector(isCameraDeviceAvailable:)])
{
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront])
{
[imagePicker setCameraDevice:UIImagePickerControllerCameraDeviceFront];
}
}
// Show the camera UI and View Finder.
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
Please check the attachment
Image is here
one of the solution is applying scaling trasnformation - here on stack maybe it will help
I don't see why you are doing these 3 things:
[self.navigationController setNavigationBarHidden:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.camPicker.view setUserInteractionEnabled:YES];
Or for that matter why you are caching the instance of UIImagePickerController (this may cause significantly higher idle memory usage for your application compared to discarding the image picker controller between uses).
Does it work better if you don't do these things?

Application crashes on changing orientation while popover is displayed.

Hi friends,
On clicking the toolbar button, my popover view appears. When i rotate the simulator to landscape orientation , following error message is displayed :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'
*** First throw call stack:
(0x1b69052 0x1868d0a 0x1b11a78 0x1b119e9 0x9ae72e 0x9affcb 0x9b26eb 0x281a39 0x1b34885 0x1b347a8 0x1c61aa 0x5490d8 0x54d499 0x54d584 0x11ede00 0x15ff4f0 0x1aa0833 0x1a9fdb4 0x1a9fccb 0x209a879 0x209a93e 0x51ca9b 0x29dd 0x2955)
Code to handle my button event is :
-(IBAction)name:(id)sender
{
if ([_popover isPopoverVisible])
{
[_popover dismissPopoverAnimated:YES];
}
else {
task * content = [[task alloc] init];
content.navigationItem.title =#"name";
[content setDelegate:self];
navController = [[UINavigationController alloc] initWithRootViewController: content];
_popover = [[UIPopoverController alloc]
initWithContentViewController:navController];
_popover. popoverContentSize=CGSizeMake(350, 480);
[_popover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Thanks..
Here you need to add code to dismiss the popover from the view when you changing the orientation.
if ([_popover isPopoverVisible])
{
[_popover dismissPopoverAnimated:YES];
}
So, put your code in the method shouldAutorotateToInterfaceOrientation() when changing the orientation and it will work.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([_popover isPopoverVisible])
{
[_popover dismissPopoverAnimated:YES];
}
return YES;
}
If you have any more questions then feel free to ask.