TTMSFMXNativeCameraViewController
The TTMSFMXNativeCameraViewController
is a view controller that is capable of rendering a preview of the input of a camera device. After dropping the camera component on the form, a few initialization steps are necessary:
Starting from iOS 10 a new NSCameraUsageDescription
key is necessary on order to correctly initialize the camera and prevent the application from crashing. This key needs to be added to each individual project. Start by going to the project options and go to version info. Scroll to the bottom, right-click and select “Add Key”.
A dialog will popup, prompting for the new version info key. Fill in “NSCameraUsageDescription”.
After clicking “OK”, the new entry still needs a value, which can be anything descriptive for your application. In the demo, we have added “Uses the camera for taking photos and scanning barcodes”
After configuring the project, the camera needs to be initialized. This is done via the InitializeCamera
call:
The additional parameter determines if the camera preview can be started or not. Initialization is only necessary once during during the lifetime of an application. The authorization based on the NSCameraUsageDescription
(iOS 10 and newer) will prompt for camera access. As soon as the application has been granted camera access the application has a correctly initialized camera. After initialization, the OnInitialized
event is called. If for some reason initialization fails, or the user has not granted permission to access the camera, a dialog is shown during authentication to determine if the user still wants to access the camera.
In the popup version, the initialization is automatically started. To start the popup, call one of the Show* methods that can be popped up from on a native UIBarButtonItem
or a TControl
. On iPad, a popup can be shown that covers a section of the screen. The PopupWidth
and PopupHeight
properties can be used to set the width and height of the popup. On iPhone, all calls will automatically show the popup full screen, as popups are not supported on iPhone devices.
When taking a photo programmatically with CapturePhoto
or with the capture photo button in the popup version, the OnCapturePhoto
event will be triggered. Additional events are available to speed up the process of capturing a photo (OnCapturePhotoData
, OnCapturePhotoStream
).