设置用户权限请求:
在Info.plist文件中添加Privacy - Camera Usage Description和Privacy - Photo Library Usage Description字段
设置代理:
class BasicPhotoViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
代码实现:
- 让用户选择从相册上传照片或是拍照
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) alert.addAction(UIAlertAction(title: "打开相机", style: .default, handler: { (alertCamera) in let picker = UIImagePickerController() picker.delegate = self picker.sourceType = .camera picker.allowsEditing = true if UIImagePickerController.isSourceT