Hello,
Here I answer this question by myself, hope my answer can help someone who also meets this issue.
Set QMAKE_INFO_PLIST in your pro file.
Please refer https://doc.qt.io/qt-6/ios-platform-notes.html#info-plist-with-qmake
Make one function to check camera permission.
For example,
void MainWindow::checkCameraPermission(void)
{ // please refer https://code.qt.io/cgit/qt/qtmultimedia.git/tree/examples/multimedia/camera?h=6.7
#if QT_CONFIG(permissions)
QCameraPermission cameraPermission;
switch (qApp->checkPermission(cameraPermission)) {
case Qt::PermissionStatus::Undetermined:
qApp->requestPermission(cameraPermission, this, &MainWindow::checkCameraPermission);
return;
case Qt::PermissionStatus::Denied:
std::cout << "Camera permission is not granted!" << std::endl;
return;
case Qt::PermissionStatus::Granted:
std::cout << "Camera permission is granted!" << std::endl;
break;
}
#endif
}
Make one function to check camera permission status.
For example,
void MainWindow::checkAuthorizationStatus(void)
{
#if QT_CONFIG(permissions)
QCameraPermission cameraPermission;
Qt::PermissionStatus auth_status = Qt::PermissionStatus::Undetermined;
while(true)
{
QThread::msleep(1);
auth_status = qApp->checkPermission(cameraPermission);
if(auth_status == Qt::PermissionStatus::Undetermined)
continue;
break;
}
#endif // if QT_CONFIG
}
Before searching your camera, call the following functions,
checkCameraPermission();
checkAuthorizationStatus();
At my side, this issue had been solved.
Thanks.
Have a nice day.