I am using Xcode 10, swift 5. I have a tableViewController that allows a user to tap, swipe left and right. When the swipe right it reveals a leading button that says complete. When the user taps the button a share dialog appears and allows them to share the work. I am struggling to implement a UIPickerController that allows the user to take a picture of their project and embed it in the share dialog.
override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let complete = UIContextualAction.init(style: .normal, title: "Complete") { (action, view, completion) in
let completedTxt = "Look at what I fixed, thanks to @DIY Home Repair!"
let vc = UIImagePickerController()
vc.sourceType = .camera
vc.allowsEditing = false
vc.delegate = self
self.present(vc, animated: true)
let activityController = UIActivityViewController(activityItems: [completedTxt, ], applicationActivities: nil)
self.present(activityController, animated: true, completion: nil)
completion(true) // Completion
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
picker.dismiss(animated: true)
guard let image = info[.originalImage] as? UIImage else {
print("No image found")
return
}
// print out the image size as a test
print(image.size)
}
}
The code displays the camera and allows the user to take a picture but the picture goes no where and the share dialog doesn't appear. When I remove the code for the UIPickerController the share dialog appears with the pre-populated text.
Its because when you present a controller there is already a UI task in motion and hence you cannot present 2 controller at once.
according to your problem you should put
UIActivityViewControllerat thedidFinishPickingMediaWithInfomethod so that you can add your image in the share sheet.