浏览代码

pressing video option in chatview now asks for permissions and opens native video library

Bastian van de Wetering 6 年之前
父节点
当前提交
ecf49bb60b
共有 1 个文件被更改,包括 35 次插入2 次删除
  1. 35 2
      deltachat-ios/Coordinator/AppCoordinator.swift

+ 35 - 2
deltachat-ios/Coordinator/AppCoordinator.swift

@@ -8,6 +8,8 @@
 
 import UIKit
 import ALCameraViewController
+import Photos
+import MobileCoreServices
 
 
 class AppCoordinator: NSObject, Coordinator, UITabBarControllerDelegate {
@@ -370,7 +372,7 @@ class GroupChatDetailCoordinator: Coordinator {
 	}
 }
 
-class ChatViewCoordinator: Coordinator {
+class ChatViewCoordinator: NSObject, Coordinator {
 	let navigationController: UINavigationController
 	let chatId: Int
 
@@ -445,10 +447,39 @@ class ChatViewCoordinator: Coordinator {
 
 	}
 	func showVideoPicker() {
-		
+		if PHPhotoLibrary.authorizationStatus() != .authorized {
+			PHPhotoLibrary.requestAuthorization{status in
+				DispatchQueue.main.async() { [weak self] in
+					switch status {
+					case  .denied,.notDetermined,.restricted:
+						print("denied")
+					case .authorized:
+						self?.presentVideoLibrary()
+					}
+				}
+			}
+		} else {
+			presentVideoLibrary()
+		}
+	}
+
+	private func presentVideoLibrary() {
+		if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
+			let videoPicker = UIImagePickerController()
+			videoPicker.title = "Videos"
+			videoPicker.delegate = self
+			videoPicker.sourceType = .photoLibrary
+			videoPicker.mediaTypes = [kUTTypeMovie as String, kUTTypeVideo as String]
+			navigationController.present(videoPicker, animated: true, completion: nil)
+		}
 	}
 }
 
+extension ChatViewCoordinator: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
+
+
+}
+
 class NewGroupCoordinator: Coordinator {
 	let navigationController: UINavigationController
 
@@ -467,6 +498,8 @@ class NewGroupCoordinator: Coordinator {
 	}
 }
 
+
+
 class GroupNameCoordinator: Coordinator {
 	let navigationController: UINavigationController