ios - 在 iOS 模拟器中测试 iPhone 相机?

标签 ios objective-c iphone

是否可以更新此代码以在模拟器中运行?现在,当应用程序到达代码中的这一点时,我正在处理的应用程序就会崩溃。我们是否可以添加 nslog 语句来允许我测试此功能?我需要在 iPad 和模拟器上同时进行测试,但是当我到达此代码时模拟器崩溃了。

- (void)snapStillImage //this is being called on did load
{
dispatch_async([self sessionQueue], ^{
    // Update the orientation on the still image output video connection before capturing.
    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];
    // Flash set to Auto for Still Capture
    [ViewController5 setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];
    // Capture a still image.
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
        if (imageDataSampleBuffer)
        {
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];

            photo.image = [[UIImage alloc] initWithData:imageData];
            [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[photo.image CGImage] orientation:(ALAssetOrientation)[photo.image imageOrientation] completionBlock:nil];
            [self uploadPhoto];
}
    }];
});
}

例如,这里是允许测试 UIImage 选择器的方法,但我正在使用 AVCam...

-(void)takePhoto {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#else
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
imagePickerController.editing = YES;
imagePickerController.delegate = (id)self;

[self presentModalViewController:imagePickerController animated:YES];
}

最佳答案

不,你不能在模拟器中使用相机。当尝试加载相机且硬件不存在时,它会崩溃。您需要使用设备来实现所有这些功能。如果您只需要相机,iPod touch 是一个很好的解决方案。

关于ios - 在 iOS 模拟器中测试 iPhone 相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724653/

相关文章:

objective-c - 仅展开 NSOutlineView 中的根节点

ios - 使用 webview 在 iOS 应用程序中伪造位置?

ios - 观察 UITableViewCell 中 NSArray 的变化

ios - 调用方法时无法识别的选择器

iOS:仅更改少数弹出 View 的方向

jquery - Cordova iOS onResume 在启动时触发并导致应用程序崩溃

ios - map 链接快速回到用户位置

iphone - 将 UIActionSheet 选项连接到操作的正确方法

iphone - 在 iPhone App Store 上启动应用程序的最佳实践

ios - 将 UIDatePicker countDownTimer 默认值设置为 1 分钟