캡쳐 및 이미지 저장 기능을 사용하여 앱에서 카메라 인터페이스를 원하지만이 앱을 실행할 때 아무 것도 얻을 수 없으며 빌드가 오류없이 성공적이지만 아무 것도 viewController에 표시되지 않습니다. .ios 카메라 app swift 3
0
A
답변
0
class ViewController: UIViewController , UINavigationControllerDelegate, UIImagePickerControllerDelegate{
@IBOutlet var imageView: UIImageView!
@IBOutlet var TakePhoto: UIButton!
var imagePick: UIImagePickerController!
var newMedia: Bool?
@IBAction func TakePhoto(_ sender: AnyObject){
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera){
let imagePick = UIImagePickerController()
imagePick.delegate = self
imagePick.sourceType = UIImagePickerControllerSourceType.camera
imagePick.mediaTypes = [kUTTypeImage as String]
imagePick.allowsEditing = false
self.present(imagePick, animated: true, completion: nil)
newMedia = true
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
if mediaType.isEqual(to: kUTTypeImage as String){
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
imageView.image = image
if(newMedia == true){
UIImageWriteToSavedPhotosAlbum(image, self, #selector(ViewController.image(image:didFinishSavingWithError:contextInfo:)), nil)
} //else if mediaType.isEqual(to: kUTTypeMovie as String)
self.dismiss(animated: true, completion: nil)
}
}
func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafeRawPointer){
if error != nil{
let alert = UIAlertController(title: "Save Failed", message: "Failed to save the image", preferredStyle: UIAlertControllerStyle.alert)
let cancelAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alert.addAction(cancelAction)
self.present(alert, animated: true, completion: nil)
}
}
}는 당신의 Info.plist에서 카메라를 사용할 수있는 권한을 설정 했습니까? 왜
이 함께 IBOutlet가 올바르게 연결된되어 그것을 사용 설명과 함께 카메라 사용법 설명, String 형 -
나는 키 개인 정보 보호를 넣어 의미? – JAL
예, 연결되어 있습니다. – Kartic