UIImagePickerController,检查相机 [英] UIImagePickerController,Check camera
本文介绍了UIImagePickerController,检查相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-(void)viewDidLoad
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.showsCameraControls = NO;
[self.view addSubview:imagePicker.view];
}
else
{
// UIAlertView…
}
}
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:NO completion:NO];
}
我想在没有相机的情况下发出警报.iPhone应用程序启动并在此代码中移动.但是,崩溃(此错误>
I want to put out an alert when you do not have a camera. IPhone app launch and move in this code. But, Crash (This Error >
返回UIApplicationMain(argc,argv,nil,NSStringFromClass([CameraAppDelegate class]));>在模拟器中运行时,线程1:发出信号SIGABRT)
.
这是为什么?
推荐答案
使用此代码,并在 .h
文件
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.wantsFullScreenLayout = YES;
[self presentModalViewController:picker animated:YES];
}
else
{
UIAlertView *altnot=[[UIAlertView alloc]initWithTitle:@"Camera Not Available" message:@"Camera Not Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
altnot.tag=103;
[altnot show];
[altnot release];
}
这篇关于UIImagePickerController,检查相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文