I use the TMSFNCWXCamera component. Under Android it works perfect, but under iOS every time i start the camera. It ask for permission after the first start of my App. When the App is running and i start the camera againg, there is not message. But if i close the App and restart it again, the system message apears again. The camera permission is set for the App, so the question should not apears!
At the time the component was developed, there was no API exposed that would allow a similar permission handling to Android. We'll investigate to see if this can be improved now.
{$IFDEF iOS}
PROCEDURE TfrmMain.CheckGranted(granted: Boolean);
BEGIN
IF granted THEN BEGIN
paProperties.Enabled := False;
tiTimoutScannQR.Enabled := True;
TMSFNCWXCamera.Visible := True;
TMSFNCWXCamera.Start;
END ELSE BEGIN
TDialogService.ShowMessage('Der Zugriff auf die Kamera ist nicht erlaubt.');
END;
END;
FUNCTION TfrmMain.RequestCameraPermission: Boolean;
VAR
AuthorizationStatus: AVAuthorizationStatus;
BEGIN
AuthorizationStatus := TAVCaptureDevice.OCClass.authorizationStatusForMediaType(AVMediaTypeVideo);
Result := (AuthorizationStatus = AVAuthorizationStatusAuthorized);
IF Result THEN BEGIN
paProperties.Enabled := False;
tiTimoutScannQR.Enabled := True;
TMSFNCWXCamera.Visible := True;
TMSFNCWXCamera.Start;
END ELSE BEGIN
TAVCaptureDevice.OCClass.requestAccessForMediaType(AVMediaTypeVideo, CheckGranted);
END;
END;
{$ENDIF}
PROCEDURE TfrmMain.btnScanQRClick(Sender: TObject);
BEGIN
{$IFDEF iOS}
RequestCameraPermission;
{$ELSE}
PermissionsService.RequestPermissions([FPermissionCamera], MakePicturePermissionRequestResult, DisplayRationale);
{$ENDIF}
END;
So i can check if the camera access are granted, but every time i call TMSFNCWXCamera.Start; the iOS shows the system message to ask for permission.
I meant an API for WKWebView (that hosts the camera) that allows to accept the permission requests automatically instead of showing a prompt. An API like that was non-existent at the time of the development that is why WKWebView always asks for permissions no matter what.
As I said, we'll look to see if we can improve this now.
Yes I am aware of that, but ChatGPT suggested me a code that was very close to the effective solution. Unfortunately I had no success with Google and Co, but maybe I just asked the wrong questions. ChatGPT pointed me in the right direction, and after all, that's what it's all about. I don't expect a turnkey answer.
We were able to implement a solution similar to Android. However, the necessary API is only available from iOS 15 so starting from the next release the minimum required iOS version for TTMSFNCWXCamera will be iOS 15.