gpt4 book ai didi

ios - 源类型 1 不可用

转载 作者:IT王子 更新时间:2023-10-29 07:42:17 26 4
gpt4 key购买 nike

我有一个适用于 iPhone 和 iPad 的应用程序,当我尝试在适用于 iPad 的 UIPopoverController 中加载 UIPickerViewController 时,出现异常“Source type 1 not available” .即使使用该设备也会遇到问题。

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

最佳答案

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

 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:

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
}

不用担心,它会在设备上正常运行!

关于ios - 源类型 1 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13564027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com