@oyalhi Я даже не вошел в систему с Apple ID. Устройство iphone полностью сброшено как новое.

Version 3
Версия XCode 8.3.3 (8E3004b)

Этот вопрос был задан и дан ответ ранее. Тем не менее, я не могу найти способ исправить эту ошибку.«Создание формата изображения с неизвестным типом - ошибка» с UIImagePickerController

Когда новая фотография выбирается из библиотеки фотографий, я получаю эту ошибку

Универсальный Создание формата изображения с неизвестным типом является ошибкой.

Я выбираю фотографию, и когда я нажимаю «Выбрать», я получаю сообщение об ошибкеfunc takePhoto где я делаю это назначениеself?.imgView.image = newImage

фатальная ошибка: неожиданно обнаружен ноль при развертывании необязательного значения Печать описания newImage: выражение породило ошибку: ошибка: /var/folders/s0/xq_zc7l56m1__n1qjk29p6tw0000gn/T/./lldb/2631/expr1.swift:1:80: ошибка: использование необъявленного типа 'UIKit' Swift._DebuggerSupport.stringForPrintObject (Swift.UnsafePointer> (bitPattern: 0x118055200) !. pointee) ^ ~~~~

typealias imagePickerHelperCompletion = ((UIImage?) -> Void)!

class ImagePickerHelper: NSObject {

 weak var viewController: UIViewController!
 var cameraFlashMode: UIImagePickerControllerCameraFlashMode   //flash, no flash
 var photoLibraryIsVisible: Bool
 var cameraDevice: UIImagePickerControllerCameraDevice //front, back camera
 var completion: imagePickerHelperCompletion


   init(viewController: UIViewController, cameraFlashMode:UIImagePickerControllerCameraFlashMode, photoLibraryIsVisible: Bool,cameraDevice: UIImagePickerControllerCameraDevice, completion: imagePickerHelperCompletion) {

    self.viewController = viewController
    self.completion = completion
    self.cameraFlashMode = cameraFlashMode
    self.photoLibraryIsVisible = photoLibraryIsVisible
    self.cameraDevice = cameraDevice

    //super.init() implemented by subclasses to initializer a new object (the receiver) immediately after memory has been allocated
    super.init()

    self.showPhotoSourceSelection()
}


//show camera or photo library
func showPhotoSourceSelection() {

    let actionSheet = UIAlertController(title: "Take new photo", message: "Would you like to open \n Camera or Photo Library?", preferredStyle: .actionSheet)

    let cameraAction = UIAlertAction(title: "Camera", style: .default) { (action) in
        self.showImagePicker(sourceType: .camera)
    }

    let photoLibraryAction = UIAlertAction(title: "Photo Library", style: .default) { (action) in
        self.showImagePicker(sourceType: .photoLibrary)
    }

    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in  }

        actionSheet.addAction(cameraAction)
    if photoLibraryIsVisible == true { actionSheet.addAction(photoLibraryAction) }
        actionSheet.addAction(cancelAction)
      viewController.present(actionSheet, animated: true, completion: nil)
}



func showImagePicker(sourceType: UIImagePickerControllerSourceType) {

    let imagePicker = UIImagePickerController()
    imagePicker.allowsEditing = true //user can crop the image, or do some editing
    imagePicker.sourceType = sourceType
    imagePicker.mediaTypes = [kUTTypeImage as String]
    imagePicker.delegate = self

      if imagePicker.sourceType == .camera {
         imagePicker.cameraFlashMode = cameraFlashMode
         imagePicker.cameraDevice = self.cameraDevice
    }
    viewController.present(imagePicker, animated: true, completion: nil)
 }
}//end of class



 extension ImagePickerHelper: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    viewController.dismiss(animated: true, completion: nil)
}



//if user did take a photo
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
    print(info)
  //prints out ["UIImagePickerControllerEditedImage": <UIImage: 0x610000294320> size {746, 498} orientation 0 scale 1.000000, "UIImagePickerControllerMediaType": public.image, "UIImagePickerControllerCropRect": NSRect: {{0, 0}, {2661, 1779}}, "UIImagePickerControllerReferenceURL": assets-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG, "UIImagePickerControllerOriginalImage": <UIImage: 0x610000299320> size {2668, 1780} orientation 0 scale 1.000000]



    if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
        completion(image)
        viewController.dismiss(animated: true, completion: nil)

    } else if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
          viewController.dismiss(animated: true, completion: nil)
          completion(image)

        } else {
        print("something is wrong line \(#line)")
       }
    }


}//end of extension






class ProfileViewController: UITableViewController {

  var imagePickerHelper: ImagePickerHelper!
  override func viewDidLoad() {
     super.viewDidLoad()
 }

  @IBAction func takePhoto(_ sender: Any) {

     //create instance of ImagePickerHelper and take photo, or get it from photoLibrary
      imagePickerHelper = ImagePickerHelper(  viewController: self, cameraFlashMode: .auto,photoLibraryIsVisible: true, cameraDevice: .front,
        completion: { [weak self] (newImage) in
     })
   }
}//end of class

Ответы на вопрос(0)

Ваш ответ на вопрос