iOS, Swift
Swift ) Source type 에러 - EEYatHo iOS
EEYatHo
2021. 9. 3. 10:36
반응형
UIImagePickerController 로 카메라를 여는 소스를 작성할 때 요따구로 썼었는데,
( iPad 부분은 덤 )
camera.sourceType = .camera
camera.allowsEditing = true
if UIDevice.current.userInterfaceIdiom == .pad { //디바이스 타입이 iPad일때
if let popoverController = camera.popoverPresentationController {
popoverController.sourceView = view
popoverController.sourceRect = CGRect(x: view.bounds.midX, y: view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
}
present(camera, animated: true, completion: nil)
시뮬레이터에서 터진다.
시뮬레이터는 카메라가 없으니 무반응이거나, 경고 메세지 좀 뜨겠지~ 했는데 터져버린다.
아무리 그래도 터지는건 좀 아니지 -ㅅ-
해당 sourceType이 가능한지 아닌지 먼저 체크하는 것이 가능
if UIImagePickerController.isSourceTypeAvailable(.camera){
camera.sourceType = .camera
camera.allowsEditing = true
if UIDevice.current.userInterfaceIdiom == .pad { //디바이스 타입이 iPad일때
if let popoverController = camera.popoverPresentationController {
popoverController.sourceView = view
popoverController.sourceRect = CGRect(x: view.bounds.midX, y: view.bounds.midY, width: 0, height: 0)
popoverController.permittedArrowDirections = []
}
}
present(camera, animated: true, completion: nil)
}
이러면, 터지진 않고 무반응이다.