瀏覽代碼

allow to take a selfie as avatar image

cyberta 5 年之前
父節點
當前提交
8cb6080137

+ 1 - 1
deltachat-ios/Controller/EditSettingsController.swift

@@ -144,7 +144,7 @@ class EditSettingsController: UITableViewController, MediaPickerDelegate {
       }
 
       private func cameraButtonPressed(_ action: UIAlertAction) {
-        ///TODO implement me!
+        coordinator?.showCamera(delegate: self)
       }
 
     private func onAvatarTapped() {

+ 4 - 0
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -206,6 +206,10 @@ class EditSettingsCoordinator: Coordinator {
     func showPhotoPicker(delegate: MediaPickerDelegate) {
         mediaPicker.showImageCropper(delegate: delegate)
     }
+
+    func showCamera(delegate: MediaPickerDelegate) {
+        mediaPicker.showCamera(delegate: delegate)
+    }
 }
 
 

+ 28 - 1
deltachat-ios/Helper/MediaPicker.swift

@@ -24,7 +24,7 @@ class MediaPicker: NSObject, UINavigationControllerDelegate, UIImagePickerContro
                                                     minimumSize: CGSize(width: 70, height: 70))
 
         let controller = CameraViewController.imagePickerViewController(croppingParameters: croppingParameters,
-                                                                        completion: { [weak self] image, asset in
+                                                                        completion: { [weak self] image, _ in
                                                                             if let image = image {
                                                                                 self?.delegate?.onImageSelected(image: image)
                                                                             }
@@ -33,6 +33,33 @@ class MediaPicker: NSObject, UINavigationControllerDelegate, UIImagePickerContro
         navigationController.present(controller, animated: true, completion: nil)
     }
 
+    func showCamera(delegate: MediaPickerDelegate) {
+        if UIImagePickerController.isSourceTypeAvailable(.camera) {
+            let croppingParameters = CroppingParameters(isEnabled: true,
+            allowResizing: true,
+            allowMoving: true,
+            minimumSize: CGSize(width: 70, height: 70))
+            let cameraViewController = CameraViewController(croppingParameters: croppingParameters,
+                                                            allowsLibraryAccess: false,
+                                                            allowsSwapCameraOrientation: true,
+                                                            allowVolumeButtonCapture: false,
+                                                            completion: { [weak self] image, _ in
+                                                                if let image = image {
+                                                                    self?.delegate?.onImageSelected(image: image)
+                                                                }
+                                                                self?.navigationController.dismiss(animated: true, completion: self?.delegate?.onDismiss)})
+            self.delegate = delegate
+            navigationController.present(cameraViewController, animated: true, completion: nil)
+        } else {
+            let alert = UIAlertController(title: String.localized("chat_camera_unavailable"), message: nil, preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: String.localized("ok"), style: .cancel, handler: { _ in
+                self.navigationController.dismiss(animated: true, completion: nil)
+            }))
+            navigationController.present(alert, animated: true, completion: nil)
+        }
+    }
+
+
     func showPhotoLibrary(delegate: MediaPickerDelegate) {
         if PHPhotoLibrary.authorizationStatus() != .authorized {
             PHPhotoLibrary.requestAuthorization { status in