加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – UIImagePickerController,检查相机

发布时间:2020-12-14 19:30:18 所属栏目:百科 来源:网络整理
导读:-(void)viewDidLoad{ if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { imagePicker = [[UIImagePickerController alloc] init]; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imag
-(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应用程序启动并移动此代码.
但是,崩溃(此错误>

返回UIApplicationMain(argc,argv,nil,NSStringFromClass([CameraAppDelegate class])); >线程1:信号SIGABRT)在模拟器中运行.

为什么是这样?

解决方法

使用此代码并在.h文件中添加UIImagePickerControllerDelegate委托

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];

    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读