キャプチャして画像の機能を持つアプリでカメラインターフェイスを使用したいが、このアプリを実行すると何も取得できず、ビルドはエラーなく成功するが、viewControllerに何も表示されない。ios Camera app swift 3
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)
}
}
}
は、あなたのIBOutletが適切にフックアップされ、それを使用している説明とカメラの使用説明、String型 -
私はキープライバシーを置くことを意味ですか? – JAL
はい、接続が良好です。 – Kartic