首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >源类型%1不可用

源类型%1不可用
EN

Stack Overflow用户
提问于 2012-11-26 19:35:30
回答 4查看 31.2K关注 0票数 48

我有一个适用于iPhone和iPad的应用程序,当我尝试在用于iPad的UIPopoverController中加载一个UIPickerViewController时,我得到了异常“源类型1不可用”。即使使用设备也会遇到问题。

代码语言:javascript
复制
@try {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])  {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.delegate = self;
        imagePicker.allowsEditing = NO;

        self.tempComp = component;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            [self presentModalViewController:imagePicker animated:YES];
        }else {
            // We are using an iPad
            popoverController=[[UIPopoverController alloc] initWithContentViewController:imagePicker];
            popoverController.delegate = self;

            [popoverController presentPopoverFromRect:component.bounds inView:component permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        }
    }else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera Non Disponibile" message:@"La camera non è disponibile" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
    }
}
@catch (NSException *exception) {
    NSLog(@"Cattura eccezione %@", exception);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Eccezione" message:[NSString stringWithFormat:@"%@", exception] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    [alert show];
}
EN

回答 4

Stack Overflow用户

发布于 2013-08-05 14:35:07

这是因为你正在模拟器上打开摄像头...由于代码类似于[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera],显然模拟器没有camera...继续给出这样的警报,

代码语言:javascript
复制
 if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                          message:@"Device has no camera."
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles: nil];

    [myAlertView show];

}
else{
     //other action
}

Swift 3:

代码语言:javascript
复制
if !UIImagePickerController.isSourceTypeAvailable(.camera) {
    let alertController = UIAlertController(title: nil, message: "Device has no camera.", preferredStyle: .alert)

    let okAction = UIAlertAction(title: "Alright", style: .default, handler: { (alert: UIAlertAction!) in
    })

    alertController.addAction(okAction)
    self.present(alertController, animated: true, completion: nil)
} else {
    // Other action
}

没什么好担心的,它会在设备上正常工作!

票数 119
EN

Stack Overflow用户

发布于 2019-07-03 16:22:34

您不能将摄像机与模拟器一起使用,只能与真实设备一起使用。模拟器没有摄像头,即使Mac上有摄像头。

请使用图片库

代码语言:javascript
复制
imagePicker.sourceType = .photoLibrary

而不是

代码语言:javascript
复制
imagePicker.sourceType = .camera
票数 4
EN

Stack Overflow用户

发布于 2019-02-02 14:42:58

您是否正在尝试在iPhone模拟器中运行该应用程序?

如果是这样的话,模拟器不支持相机功能,只支持从照片库中获取照片。听起来似乎我应该构建一个自动后备,因为很多人都会尝试在模拟器上测试他们的应用程序。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13564027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档