Every now and then the Xcode developers have to make use of the iPhone camera to click pics, photos and even different types of symbols and codes like bar code and more recently the QR Codes (Quick Response codes).
The primary problem faced by the developers in writing the code that makes use of the iPhone camera is that they need the actual device every single time to test the logical working of the code ie. to make sure that the code scans the image and then returns the correct output, the developer needs to have an actual device which might not be possible at all times.
The regular code that makes use of the camera, when run on the iOS Simulator crashes the app giving the error :
'NSInvalidArgumentException', reason: 'Source type 1 not available'
This exception means that the simulator does not have a camera to execute the code and hence the app crashes.
An easy solution to this problem is the Camera Simulation.
As the name itself suggests, the Camera Simulation works to provide a camera to the iOS Simulator. The camera Simulator does not actually provides a camera for the Simulator but links the app to the photo gallery of the phone. Now the developer can save the images that needs to be tested, on the photo gallery of the iOS Simulator. So the developer can now import the images saved in the phone gallery and make sure that the code functions properly on the image.The developer can find out if the code scans the QR code correctly, how much time does the code takes to scan the QR code and how the result is displayed in the app. This eliminates the necessity of having an iPhone to test the code that makes use of the camera.
The required code for the Camera Simulation is as follows: