|
|
|
@ -92,12 +92,14 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleLibraryButtonTapped() {
|
|
|
|
|
// FIXME: We're not yet handling the case where the user only gives access to selected photos/videos
|
|
|
|
|
guard requestLibraryPermissionIfNeeded() else { return }
|
|
|
|
|
requestLibraryPermissionIfNeeded { [weak self] in
|
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
|
let sendMediaNavController = SendMediaNavigationController.showingMediaLibraryFirst()
|
|
|
|
|
sendMediaNavController.sendMediaNavDelegate = self
|
|
|
|
|
sendMediaNavController.modalPresentationStyle = .fullScreen
|
|
|
|
|
present(sendMediaNavController, animated: true, completion: nil)
|
|
|
|
|
self?.present(sendMediaNavController, animated: true, completion: nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func handleGIFButtonTapped() {
|
|
|
|
@ -727,43 +729,46 @@ extension ConversationVC : InputViewDelegate, MessageCellDelegate, ContextMenuAc
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func requestLibraryPermissionIfNeeded() -> Bool {
|
|
|
|
|
func requestLibraryPermissionIfNeeded(handler: @escaping () -> Void) {
|
|
|
|
|
let authorizationStatus: PHAuthorizationStatus
|
|
|
|
|
if #available(iOS 14, *) {
|
|
|
|
|
authorizationStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)
|
|
|
|
|
if (authorizationStatus == .notDetermined) {
|
|
|
|
|
PHPhotoLibrary.requestAuthorization(for: .readWrite) { newStatus in
|
|
|
|
|
switch newStatus {
|
|
|
|
|
case .authorized:
|
|
|
|
|
print("RYAN: Full access.")
|
|
|
|
|
break
|
|
|
|
|
case .limited:
|
|
|
|
|
print("RYAN: Limited access.")
|
|
|
|
|
break
|
|
|
|
|
case .denied:
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
// When the user chooses to select photos (which is the .limit status),
|
|
|
|
|
// the PHPhotoUI will present the picker view on the top of the front view.
|
|
|
|
|
// Since we have this ScreenLockUI showing when we request premissions,
|
|
|
|
|
// the picker view will be presented on the top of ScreenLockUI.
|
|
|
|
|
// However, the ScreenLockUI will dismiss with the permission request alert view,
|
|
|
|
|
// the picker view then will dissmiss, too. The selection process cannot be finished
|
|
|
|
|
// this way. So we add a flag (isRequestingPermission) to prevent the ScreenLockUI
|
|
|
|
|
// from showing when we request the photo library permission.
|
|
|
|
|
Environment.shared.isRequestingPermission = true
|
|
|
|
|
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
|
|
|
|
|
Environment.shared.isRequestingPermission = false
|
|
|
|
|
if ([PHAuthorizationStatus.authorized, PHAuthorizationStatus.limited].contains(status)) {
|
|
|
|
|
handler()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
authorizationStatus = PHPhotoLibrary.authorizationStatus()
|
|
|
|
|
if (authorizationStatus == .notDetermined) {
|
|
|
|
|
PHPhotoLibrary.requestAuthorization { _ in }
|
|
|
|
|
return false
|
|
|
|
|
PHPhotoLibrary.requestAuthorization { status in
|
|
|
|
|
if (status == .authorized) {
|
|
|
|
|
handler()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
switch authorizationStatus {
|
|
|
|
|
case .authorized, .limited: return true
|
|
|
|
|
case .authorized, .limited:
|
|
|
|
|
handler()
|
|
|
|
|
case .denied, .restricted:
|
|
|
|
|
let modal = PermissionMissingModal(permission: "library") { }
|
|
|
|
|
modal.modalPresentationStyle = .overFullScreen
|
|
|
|
|
modal.modalTransitionStyle = .crossDissolve
|
|
|
|
|
present(modal, animated: true, completion: nil)
|
|
|
|
|
return false
|
|
|
|
|
default: return false
|
|
|
|
|
default: return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|