我正在尝试制作一个非常简单的iphone应用程序,它显示设备的实时摄像头视图,并添加了我通过研究发现的以下代码。
-(void)viewDidLoad{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
这只会导致SIGABRT错误,我不知道如何处理。
由于以上代码似乎是实现相机视图的必要条件,是否还有其他我错过的内容?没想到只是加载相机视图会给我带来压力...... 请帮帮我。
ps.我正在使用xcode 4 btw。
答案 0 :(得分:1)
在添加
之前检查一下if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
else
{
//.....
}