我有一个与UIViewController
连接的NavigationController
,我称之为ScanViewController
。在该控制器中,我想要启动相机,并且我只在viewDidLoad
中有这个简单的代码片段,除此之外没有其他代码:
let vc = UIImagePickerController()
vc.sourceType = .camera
vc.allowsEditing = true
present(vc, animated: true)
但是在相机启动后立刻关闭并退出应用程序。输出如下。我有一个方向警告,但这不应该关闭相机,对吗?我也已经获得了相机权限,并通过在手机设置
中进行检查来验证我的应用程序已启用相机访问权限。
代码中的权限:
switch AVCaptureDevice.authorizationStatus(for: .video)
case .authorized:
print("Scan View Controller || Permission to use camera granted")
self.startCamera()
在 info.plist 中的权限:
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) needs access to your camera.</string>
还有日志:
2023-03-17 11:28:12.627212+0100 Cykelrum.se[41417:2892989] [Camera] Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
2023-03-17 11:28:12.627307+0100 Cykelrum.se[41417:2892989] [Camera] Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
2023-03-17 11:28:12.627614+0100 Cykelrum.se[41417:2892989] [Camera] Attempted to change to mode Portrait with an unsupported device (BackAuto). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
2023-03-17 11:28:12.627641+0100 Cykelrum.se[41417:2892989] [Camera] Attempted to change to mode Portrait with an unsupported device (BackWideDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
2023-03-17 11:28:13.608818+0100 Cykelrum.se[41417:2893505] XPC connection interrupted
2023-03-17 11:28:13.611892+0100 Cykelrum.se[41417:2893494] [Common] [SBSSystemServiceClient:0x282a8d080] Service suspended: the connection with the service host has been interrupted.
2023-03-17 11:28:13.612078+0100 Cykelrum.se[41417:2893494] [Common] [FBSOrientationObserverClient:0x282abbea0] Service suspended: the connection with the service host has been interrupted.
2023-03-17 11:28:14.352022+0100 Cykelrum.se[41417:2893505] [Common] [FBSOrientationObserverClient:0x282abbea0] Service suspended: the connection with the service host has been interrupted.
2023-03-17 11:28:14.352115+0100 Cykelrum.se[41417:2893505] [Common] [SBSSystemServiceClient:0x282a8d080] Service suspended: the connection with the service host has been interrupted.
2023-03-17 11:28:22.302388+0100 Cykelrum.se[41417:2893494] 10.6.0 - [FirebaseAnalytics][I-ACS800014] Cannot get flag for unregistered flag. SDK name, flag name: app_measurement, session_stitching_token_feature_enabled
2023-03-17 11:28:23.630021+0100 Cykelrum.se[41417:2893414] [connection] nw_connection_copy_connected_local_endpoint_block_invoke [C27] Client called nw_connection_copy_connected_local_endpoint on unconnected nw_connection
2023-03-17 11:28:23.630078+0100 Cykelrum.se[41417:2893414] [connection] nw_connection_copy_connected_remote_endpoint_block_invoke [C27] Client called nw_connection_copy_connected_remote_endpoint on unconnected nw_connection
2023-03-17 11:28:23.630117+0100 Cykelrum.se[41417:2893414] [connection] nw_connection_copy_protocol_metadata_internal_block_invoke [C27] Client called nw_connection_copy_protocol_metadata_internal on unconnected nw_connection
2023-03-17 11:28:24.463510+0100 Cykelrum.se[41417:2893414] [connection] nw_resolver_start_query_timer_block_invoke [C25.1.1] Query fired: did not receive all answers in time for app-measurement.com:443