Is there any way to test the iPhone camera in the simulator without having to deploy on a device? This seems awfully tedious.
有没有办法在模拟器中测试iPhone摄像头而不用在设备上部署?这似乎很乏味。
5 个解决方案
#1
106
There are a number of device specific features that you have to test on the device, but it's no harder than using the simulator. Just build a debug target for the device and leave it attached to the computer.
有许多设备特定的特性你必须在设备上测试,但这并不比使用模拟器难。只需为设备构建一个调试目标,并将其附加到计算机上。
List of actions that require an actual device:
需要实际设备的操作列表:
- the actual phone
- 实际的电话
- the camera
- 相机
- the accelerometer
- 加速度计
- real GPS data
- 真正的GPS数据
- the compass
- 指南针
- vibration
- 振动
- push notifications...
- 推送通知…
-t
- t
#2
7
I needed to test some custom overlays for photos. The overlays needed to be adjusted based on the size/resolution of the image.
我需要测试一些自定义的照片覆盖。覆盖需要根据图像的大小/分辨率进行调整。
I approached this in a way that was similar to the suggestion from Stefan, I decided to code up a "dummy" camera response.
我以一种类似于Stefan的建议的方式处理这个问题,我决定编写一个“虚拟”摄像头响应。
When the simulator is running I execute this dummy code instead of the standard "captureStillImageAsynchronouslyFromConnection".
当模拟器运行时,我执行这个伪代码,而不是标准的“capturestillimageasynchronousfromconnection”。
In this dummy code, I build up a "black photo" of the necessary resolution and then send it through the pipelined to be treated like a normal photo. Essentially providing the feel of a very fast camera.
在这个伪代码中,我构建了一个必要分辨率的“黑色照片”,然后通过流水线发送它,就像普通照片一样被处理。本质上提供了一个非常快的相机的感觉。
CGSize sz = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) ? CGSizeMake(2448, 3264) : CGSizeMake(3264, 2448);
UIGraphicsBeginImageContextWithOptions(sz, YES, 1);
[[UIColor blackColor] setFill];
UIRectFill(CGRectMake(0, 0, sz.width, sz.height));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
The image above is equivalent to a 8MP photos that most of the current day devices send out. Obviously to test other resolutions you would change the size.
上面的图像相当于当前大多数设备发出的8MP照片。显然,要测试其他分辨率,您需要更改大小。
#3
1
Nope (unless they've added a way to do it in 3.2, haven't checked yet).
没有(除非他们在3.2中添加了一种方法,还没有检查)。
#4
1
A common reason for the need of accessing the camera is to make screenshots for the AppStore.
需要访问相机的一个常见原因是为AppStore做屏幕截图。
Since the camera is not available in the simulator, a good trick ( the only one I know ) is to resize your view at the size you need, just the time to take the screenshots. You will crop them later.
由于相机在模拟器中是不可用的,所以一个很好的技巧(我知道的唯一的一个)是调整你的视图大小,你需要的大小,正好是截图的时间。你以后会修剪的。
Sure, you need to have the device with the bigger screen available.
当然,你需要有更大屏幕的设备。
The iPad is perfect to test layouts and make snapshots for all devices. Screenshots for iPhone6+ will have to be stretched a little ( scaled by 1,078125 - Not a big deal… )
iPad非常适合测试布局和为所有设备制作快照。iPhone6+的屏幕截图必须稍微拉长一点(按1078125的比例放大——没什么大不了的…)
Good link to a iOS Devices resolutions quick ref : http://www.iosres.com/
好的链接到iOS设备的决议快速参考:http://www.iosres.com/。
Edit : In a recent project, where a custom camera view controller is used, I have replaced the AVPreview by an UIImageView in a target that I only use to run in the simulator. This way I can automate screenshots for iTunesConnect upload. Note that camera control buttons are not in an overlay, but in a view over the camera preview.
编辑:在最近的一个项目中,使用了一个自定义的摄像头视图控制器,我用一个UIImageView替换了AVPreview,我只在模拟器中运行。这样我就可以为iTunesConnect上传自动截图。注意,相机控制按钮不是在覆盖层中,而是在相机预览的视图中。
The @Craig answer below describes another method that I found quite smart - It also works with camera overlay, contrarily to mine.
下面的@Craig的回答描述了另一种我觉得很聪明的方法——它也适用于相机的覆盖层,与我的相反。
#5
0
I wrote a replacement view to use in debug mode. It implements the same API and makes the same delegate callbacks. In my case I made it return a random image from my test set. Pretty trivial to write.
我编写了一个替换视图以在调试模式下使用。它实现相同的API并进行相同的委托回调。在我的例子中,我让它从我的测试集中返回一个随机图像。
#1
106
There are a number of device specific features that you have to test on the device, but it's no harder than using the simulator. Just build a debug target for the device and leave it attached to the computer.
有许多设备特定的特性你必须在设备上测试,但这并不比使用模拟器难。只需为设备构建一个调试目标,并将其附加到计算机上。
List of actions that require an actual device:
需要实际设备的操作列表:
- the actual phone
- 实际的电话
- the camera
- 相机
- the accelerometer
- 加速度计
- real GPS data
- 真正的GPS数据
- the compass
- 指南针
- vibration
- 振动
- push notifications...
- 推送通知…
-t
- t
#2
7
I needed to test some custom overlays for photos. The overlays needed to be adjusted based on the size/resolution of the image.
我需要测试一些自定义的照片覆盖。覆盖需要根据图像的大小/分辨率进行调整。
I approached this in a way that was similar to the suggestion from Stefan, I decided to code up a "dummy" camera response.
我以一种类似于Stefan的建议的方式处理这个问题,我决定编写一个“虚拟”摄像头响应。
When the simulator is running I execute this dummy code instead of the standard "captureStillImageAsynchronouslyFromConnection".
当模拟器运行时,我执行这个伪代码,而不是标准的“capturestillimageasynchronousfromconnection”。
In this dummy code, I build up a "black photo" of the necessary resolution and then send it through the pipelined to be treated like a normal photo. Essentially providing the feel of a very fast camera.
在这个伪代码中,我构建了一个必要分辨率的“黑色照片”,然后通过流水线发送它,就像普通照片一样被处理。本质上提供了一个非常快的相机的感觉。
CGSize sz = UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]) ? CGSizeMake(2448, 3264) : CGSizeMake(3264, 2448);
UIGraphicsBeginImageContextWithOptions(sz, YES, 1);
[[UIColor blackColor] setFill];
UIRectFill(CGRectMake(0, 0, sz.width, sz.height));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
The image above is equivalent to a 8MP photos that most of the current day devices send out. Obviously to test other resolutions you would change the size.
上面的图像相当于当前大多数设备发出的8MP照片。显然,要测试其他分辨率,您需要更改大小。
#3
1
Nope (unless they've added a way to do it in 3.2, haven't checked yet).
没有(除非他们在3.2中添加了一种方法,还没有检查)。
#4
1
A common reason for the need of accessing the camera is to make screenshots for the AppStore.
需要访问相机的一个常见原因是为AppStore做屏幕截图。
Since the camera is not available in the simulator, a good trick ( the only one I know ) is to resize your view at the size you need, just the time to take the screenshots. You will crop them later.
由于相机在模拟器中是不可用的,所以一个很好的技巧(我知道的唯一的一个)是调整你的视图大小,你需要的大小,正好是截图的时间。你以后会修剪的。
Sure, you need to have the device with the bigger screen available.
当然,你需要有更大屏幕的设备。
The iPad is perfect to test layouts and make snapshots for all devices. Screenshots for iPhone6+ will have to be stretched a little ( scaled by 1,078125 - Not a big deal… )
iPad非常适合测试布局和为所有设备制作快照。iPhone6+的屏幕截图必须稍微拉长一点(按1078125的比例放大——没什么大不了的…)
Good link to a iOS Devices resolutions quick ref : http://www.iosres.com/
好的链接到iOS设备的决议快速参考:http://www.iosres.com/。
Edit : In a recent project, where a custom camera view controller is used, I have replaced the AVPreview by an UIImageView in a target that I only use to run in the simulator. This way I can automate screenshots for iTunesConnect upload. Note that camera control buttons are not in an overlay, but in a view over the camera preview.
编辑:在最近的一个项目中,使用了一个自定义的摄像头视图控制器,我用一个UIImageView替换了AVPreview,我只在模拟器中运行。这样我就可以为iTunesConnect上传自动截图。注意,相机控制按钮不是在覆盖层中,而是在相机预览的视图中。
The @Craig answer below describes another method that I found quite smart - It also works with camera overlay, contrarily to mine.
下面的@Craig的回答描述了另一种我觉得很聪明的方法——它也适用于相机的覆盖层,与我的相反。
#5
0
I wrote a replacement view to use in debug mode. It implements the same API and makes the same delegate callbacks. In my case I made it return a random image from my test set. Pretty trivial to write.
我编写了一个替换视图以在调试模式下使用。它实现相同的API并进行相同的委托回调。在我的例子中,我让它从我的测试集中返回一个随机图像。