Reputation: 75
Just to make sure I have all the code right, here is my header file:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate> {
IBOutlet UIImageView *imageView;
IBOutlet UIButton *choosePhoto;
IBOutlet UIButton *takePhoto;
}
@property(nonatomic, retain) UIButton *choosePhoto;
@property(nonatomic, retain) UIButton *takePhoto;
@property(nonatomic, retain) UIImageView *imageView;
-(IBAction)getPhoto:(id)sender;
-(IBAction)takePhoto:(id)sender;
@end
And then here is my implementation:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize imageView,choosePhoto,takePhoto;
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(IBAction)getPhoto:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:picker animated:YES completion:nil];
}
-(IBAction)takePhoto:(id)sender {
UIImagePickerController *picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
picker2.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker2 animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissViewControllerAnimated:YES completion:nil];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
-(void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
I have two UIButtons
and a UIIImageView
in my interface builder. The test app builds fine, no problems at all but when I press either the choose photo or take photo buttons the app crashes. Is this just because the simulator technically does not have either or a camera or a library to of photos to choose from? This is the error it gives me: UIStatusBarStyleBlackTranslucent
is not available on this device.
Cameratest[8290:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'On iPad, UIImagePickerController must be presented via UIPopoverController
Advice is greatly appreciated!
Upvotes: 1
Views: 8451
Reputation: 265
No simulator doesn't support to simulate camera. For camera you have to run app on device
Upvotes: 0
Reputation: 7145
From Apple:
Hardware Simulation Support
iOS Simulator doesn’t simulate accelerometer or camera hardware.
Additionally, H2CO3 is right, you've got a different problem and the error message is pretty clear:
'On iPad, UIIMagePickerController must be presented via UIPopoverController'
A quick google search pointed me to the link below. Check out Zubair's response. I think you need to present the UIImagePickerController in a popover when running on iPad.
UIStatusBarStyleBlackTranslucent is not available on this device
Upvotes: 8