Reputation: 16174
I have a UICollectionView
with a CameraCell
in it as a first cell, it displays a camera preview.
I want to fix a warning in XCode console on iOS 16
, iPhone XS Max
with dual rear camera:
[Camera] Attempted to change to mode Portrait with an unsupported device (BackDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
It appears after UICollectionViewCell
with camera preview is displayed on a screen (not when CameraCell
is created). I tried to subclass UIImagePickerController
and prevent any orientation changes - didn't help.
My CameraCell
code:
final class CameraCell: UICollectionViewCell {
static var reuseIdentifier: String {
String(describing: CameraCell.self)
}
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
NSLogIfDebug("[CameraCell] Init")
}
@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
deinit {
NSLogIfDebug("[CameraCell] Deinit")
}
private lazy var imagePickerController: UIImagePickerController = {
let imgPicker = UIImagePickerController()
imgPicker.delegate = self
imgPicker.sourceType = .camera
imgPicker.cameraDevice = .rear
imgPicker.allowsEditing = false
imgPicker.showsCameraControls = false
imgPicker.cameraViewTransform = Constants.cameraViewTransform
return imgPicker
}()
private lazy var cameraContainerView: UIView = {
let view = UIView(frame: .zero)
view.clipsToBounds = true
view.translatesAutoresizingMaskIntoConstraints = false
view.isUserInteractionEnabled = true
return view
}()
private lazy var cameraView: UIView = {
// Used to return a dummy view on iPhone Simulator
let isCameraDeviceAvailable = UIImagePickerController.isCameraDeviceAvailable(UIImagePickerController.CameraDevice.rear)
guard isCameraDeviceAvailable, let view = imagePickerController.view else {
let dummyView = UIView(frame: .zero)
dummyView.translatesAutoresizingMaskIntoConstraints = false
return dummyView
}
view.frame = .zero
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private lazy var cameraImageView: UIImageView = {
let imageView = UIImageView(frame: .zero)
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .center
imageView.clipsToBounds = true
imageView.image = Constants.cameraImage
imageView.backgroundColor = .surface8Color.withAlphaComponent(Constants.cameraImageViewAlpha)
imageView.isUserInteractionEnabled = true
return imageView
}()
}
// MARK: - Private
private extension CameraCell {
enum Constants {
static let cameraImageViewAlpha = 0.4 as CGFloat
static let cameraImage = UIImage(named: "photo-camera")
static let cameraViewTransform = CGAffineTransform(scaleX: 2.0, y: 2.0)
}
func setupView() {
setupCameraContainerView()
}
func setupCameraContainerView() {
addSubview(cameraContainerView)
addConstraints([
cameraContainerView.leadingAnchor.constraint(equalTo: leadingAnchor),
cameraContainerView.trailingAnchor.constraint(equalTo: trailingAnchor),
cameraContainerView.topAnchor.constraint(equalTo: topAnchor),
cameraContainerView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
setupCameraView()
setupCameraImageView()
}
func setupCameraView() {
cameraContainerView.addSubview(cameraView)
addConstraints([
cameraView.leadingAnchor.constraint(equalTo: cameraContainerView.leadingAnchor),
cameraView.trailingAnchor.constraint(equalTo: cameraContainerView.trailingAnchor),
cameraView.topAnchor.constraint(equalTo: cameraContainerView.topAnchor),
cameraView.bottomAnchor.constraint(equalTo: cameraContainerView.bottomAnchor)
])
}
func setupCameraImageView() {
cameraContainerView.addSubview(cameraImageView)
addConstraints([
cameraImageView.leadingAnchor.constraint(equalTo: cameraContainerView.leadingAnchor),
cameraImageView.trailingAnchor.constraint(equalTo: cameraContainerView.trailingAnchor),
cameraImageView.topAnchor.constraint(equalTo: cameraContainerView.topAnchor),
cameraImageView.bottomAnchor.constraint(equalTo: cameraContainerView.bottomAnchor)
])
}
}
// MARK: - UIImagePickerControllerDelegate
extension CameraCell: UIImagePickerControllerDelegate {}
// MARK: - UINavigationControllerDelegate
extension CameraCell: UINavigationControllerDelegate {}
Upvotes: 5
Views: 6221
Reputation: 9027
I had the similar issue with this warning.
2023-04-23 18:06:11.709709+0530 [19161:1003234] [Camera] Attempted to change to mode Portrait with an unsupported device (BackDual). Auto device for both positions unsupported, returning Auto device for same position anyway (BackAuto).
2023-04-23 18:06:12.445469+0530 [19161:1003512] XPC connection interrupted
2023-04-23 18:06:12.449248+0530 [19161:1003818] [Common] [SBSSystemServiceClient:0x2807805a0] Service suspended: the connection with the service host has been interrupted.
2023-04-23 18:06:12.449309+0530 [19161:1003752] [Common] [FBSOrientationObserverClient:0x2807a7180] Service suspended: the connection with the service host has been interrupted.
2023-04-23 18:06:13.190247+0530 [19161:1003524] [Common] [FBSOrientationObserverClient:0x2807a7180] Service suspended: the connection with the service host has been interrupted.
2023-04-23 18:06:13.190388+0530 [19161:1003524] [Common] [SBSSystemServiceClient:0x2807805a0] Service suspended: the connection with the service host has been interrupted.
2023-04-23 18:06:23.256350+0530 [19161:1003525] [connection] nw_connection_copy_connected_local_endpoint_block_invoke [C11] Client called nw_connection_copy_connected_local_endpoint on unconnected nw_connection
2023-04-23 18:06:23.256474+0530 [19161:1003525] [connection] nw_connection_copy_connected_remote_endpoint_block_invoke [C11] Client called nw_connection_copy_connected_remote_endpoint on unconnected nw_connection
2023-04-23 18:06:23.256551+0530 [19161:1003525] [connection] nw_connection_copy_protocol_metadata_internal_block_invoke [C11] Client called nw_connection_copy_protocol_metadata_internal on unconnected nw_connection
But this solution works for me Info.plist has unwanted or extra keys. In my case, I have this extra key, delete that key and everything working like charm! :)
Upvotes: -3