2016-12-16 28 views
0

所以我有這個代碼將獲得照片我的畫廊或使用相機更改UIImage。UIImagePickerControllerDelegate錯誤

@IBAction func tappedCamera() { 
    print("tapped camera") 

    let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet) 

    let cameraAction = UIAlertAction(title: "Camera", style: .default, handler: { 
     (alert: UIAlertAction!) -> Void in 

     if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) { 
      self.picker.sourceType = UIImagePickerControllerSourceType.camera; 
      self.picker.allowsEditing = true 
      self.present(self.picker, animated: true, completion: nil) 
     } 

    }) 
    let galleryAction = UIAlertAction(title: "Gallery", style: .default, handler: { 
     (alert: UIAlertAction!) -> Void in 

     if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) { 
      self.picker.sourceType = UIImagePickerControllerSourceType.photoLibrary; 
      self.picker.allowsEditing = true 
      self.present(self.picker, animated: true, completion: nil) 
     } 


    }) 
    let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: { 
     (alert: UIAlertAction!) -> Void in 
     //do none 
    }) 


    optionMenu.addAction(cameraAction) 
    optionMenu.addAction(galleryAction) 
    optionMenu.addAction(cancelAction) 

    self.present(optionMenu, animated: true, completion: nil) 

} 

但是我總是得到這個錯誤,每當我嘗試捕獲照片或從圖庫中選擇一張圖片。

[Generic] Creating an image format with an unknown type is an error 
+0

1.當你捕捉到照片時,在完成拾取委託方法後,確保你將其轉換爲* Any *'didFinishPickingMediaWithInfo info:[String:Any]' 2.實現'UINavigationControllerDelegate'。 – pkc456

+0

UIImagePicker didfinishpickingimage的代理方法在哪裏? –

回答

0

我通過修復我的用戶默認值來解決它。因爲在代碼的某處我搞亂了圖像,將它們轉換爲base64字符串,然後將其保存爲用戶默認值。