marinofaggiana 4 жил өмнө
parent
commit
213fe2ebf1

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -88,6 +88,7 @@
 		F72CD63A25C19EBF00F46F9A /* NCAutoUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72CD63925C19EBF00F46F9A /* NCAutoUpload.swift */; };
 		F72D1007210B6882009C96B7 /* NCPushNotificationEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F72D1005210B6882009C96B7 /* NCPushNotificationEncryption.m */; };
 		F72D404923D2082500A97FD0 /* NCViewerNextcloudText.swift in Sources */ = {isa = PBXBuildFile; fileRef = F72D404823D2082500A97FD0 /* NCViewerNextcloudText.swift */; };
+		F733598125C1C188002ABA72 /* NCAskAuthorization.swift in Sources */ = {isa = PBXBuildFile; fileRef = F733598025C1C188002ABA72 /* NCAskAuthorization.swift */; };
 		F733B65221997CC2001C1FFA /* TLPhotoPicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F733B65121997CC1001C1FFA /* TLPhotoPicker.framework */; };
 		F7362A1F220C853A005101B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7362A1E220C853A005101B5 /* LaunchScreen.storyboard */; };
 		F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7381EDA218218C9000B1560 /* NCOffline.swift */; };
@@ -451,6 +452,7 @@
 		F72E0B9C21AD60BC00898D7B /* WeScan.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WeScan.framework; path = Carthage/Build/iOS/WeScan.framework; sourceTree = "<group>"; };
 		F7320934201B812F008A0888 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Localizable.strings; sourceTree = "<group>"; };
 		F732093B201B81E4008A0888 /* es-419 */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "es-419"; path = "es-419.lproj/Localizable.strings"; sourceTree = "<group>"; };
+		F733598025C1C188002ABA72 /* NCAskAuthorization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAskAuthorization.swift; sourceTree = "<group>"; };
 		F733B65121997CC1001C1FFA /* TLPhotoPicker.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TLPhotoPicker.framework; path = Carthage/Build/iOS/TLPhotoPicker.framework; sourceTree = "<group>"; };
 		F7362A1E220C853A005101B5 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
 		F736B551234DCF57008A5C9F /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = Carthage/Build/iOS/Alamofire.framework; sourceTree = "<group>"; };
@@ -1279,6 +1281,7 @@
 				F7514EDB1C7B1336008F3338 /* CCHud.m */,
 				F7053E3C1C639DF500741EA5 /* CCUtility.h */,
 				F7053E3D1C639DF500741EA5 /* CCUtility.m */,
+				F733598025C1C188002ABA72 /* NCAskAuthorization.swift */,
 				F78E7064219F096B006F23E4 /* NCAvatar.swift */,
 				F765608E23BF813500765969 /* NCContentPresenter.swift */,
 				F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */,
@@ -2028,6 +2031,7 @@
 				F7AE00F8230E81CB007ACF8A /* NCBrowserWeb.swift in Sources */,
 				F70A58BE24D0349500DED00D /* NCCapabilitiesViewController.swift in Sources */,
 				F752011D25480387000BF3A7 /* NCViewerVideo.swift in Sources */,
+				F733598125C1C188002ABA72 /* NCAskAuthorization.swift in Sources */,
 				370D26AF248A3D7A00121797 /* NCImageCellProtocol.swift in Sources */,
 				F77B0DF51D118A16002130FE /* CCUtility.m in Sources */,
 				F710D1FE24057E5E00A6033D /* NCActionSheetHeader.swift in Sources */,

+ 1 - 1
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -114,7 +114,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
             NCMenuAction(
                 title: NSLocalizedString("_create_voice_memo_", comment: ""), icon: UIImage(named: "microphone")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
                     
-                    NCUtility.shared.askAudioRecordPermission(viewController: viewController) { (permissions) in
+                    NCAskAuthorization.shared.askAuthorizationAudioRecord(viewController: viewController) { (permissions) in
                         if permissions {
                             let fileName = CCUtility.createFileNameDate(NSLocalizedString("_voice_memo_filename_", comment: ""), extension: "m4a")!
                             let viewController = UIStoryboard(name: "NCAudioRecorderViewController", bundle: nil).instantiateInitialViewController() as! NCAudioRecorderViewController

+ 112 - 0
iOSClient/Utility/NCAskAuthorization.swift

@@ -0,0 +1,112 @@
+//
+//  NCAskAuthorization.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 27/01/21.
+//  Copyright © 2021 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import Foundation
+
+class NCAskAuthorization: NSObject {
+    @objc static let shared: NCAskAuthorization = {
+        let instance = NCAskAuthorization()
+        return instance
+    }()
+    
+    func askAuthorizationAudioRecord(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
+        
+        switch AVAudioSession.sharedInstance().recordPermission {
+        case AVAudioSession.RecordPermission.granted:
+            completion(true)
+            break
+        case AVAudioSession.RecordPermission.denied:
+            let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_microphone_", comment: ""), preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { action in
+                UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
+                completion(false)
+            }))
+            alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { action in
+                completion(false)
+            }))
+            viewController.present(alert, animated: true, completion: nil)
+            break
+        case AVAudioSession.RecordPermission.undetermined:
+            AVAudioSession.sharedInstance().requestRecordPermission { (allowed) in
+                DispatchQueue.main.async {
+                    if allowed {
+                        completion(true)
+                    } else {
+                        completion(false)
+                    }
+                }
+            }
+            break
+        default:
+            completion(false)
+            break
+        }
+    }
+    
+    func askAuthorizationPhotoLibrary(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
+     
+        switch PHPhotoLibrary.authorizationStatus() {
+        case PHAuthorizationStatus.authorized:
+            completion(true)
+            break
+        case PHAuthorizationStatus.denied, PHAuthorizationStatus.limited, PHAuthorizationStatus.restricted:
+            let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_photolibrary_", comment: ""), preferredStyle: .alert)
+            alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { action in
+                UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
+                completion(false)
+            }))
+            alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { action in
+                completion(false)
+            }))
+            viewController.present(alert, animated: true, completion: nil)
+            break
+        case PHAuthorizationStatus.notDetermined:
+            PHPhotoLibrary.requestAuthorization { (allowed) in
+                DispatchQueue.main.async {
+                    if allowed == PHAuthorizationStatus.authorized {
+                        completion(true)
+                    } else {
+                        completion(false)
+                    }
+                }
+            }
+            break
+        default:
+            completion(false)
+            break
+        }
+    }
+    
+    func askAuthorizationLocationManager(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
+        
+        switch CLLocationManager.authorizationStatus() {
+        case CLAuthorizationStatus.authorizedAlways:
+            completion(true)
+            break
+        case CLAuthorizationStatus.notDetermined:
+            break
+        default:
+            break
+        }
+    }
+}

+ 0 - 70
iOSClient/Utility/NCUtility.swift

@@ -448,75 +448,5 @@ class NCUtility: NSObject {
             try? originalImage?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathIcon))
         }
     }
-    
-    func askAudioRecordPermission(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
-        
-        switch AVAudioSession.sharedInstance().recordPermission {
-        case AVAudioSession.RecordPermission.granted:
-            completion(true)
-            break
-        case AVAudioSession.RecordPermission.denied:
-            let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_microphone_", comment: ""), preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { action in
-                UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
-                completion(false)
-            }))
-            alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { action in
-                completion(false)
-            }))
-            viewController.present(alert, animated: true, completion: nil)
-            break
-        case AVAudioSession.RecordPermission.undetermined:
-            AVAudioSession.sharedInstance().requestRecordPermission { (allowed) in
-                DispatchQueue.main.async {
-                    if allowed {
-                        completion(true)
-                    } else {
-                        completion(false)
-                    }
-                }
-            }
-            break
-        default:
-            break
-        }
-    }
-    
-    func askPhotoLibraryPermission(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
-     
-        switch PHPhotoLibrary.authorizationStatus() {
-        case PHAuthorizationStatus.authorized:
-            completion(true)
-            break
-        case PHAuthorizationStatus.denied, PHAuthorizationStatus.limited, PHAuthorizationStatus.restricted:
-            let alert = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_err_permission_photolibrary_", comment: ""), preferredStyle: .alert)
-            alert.addAction(UIAlertAction(title: NSLocalizedString("_open_settings_", comment: ""), style: .default, handler: { action in
-                UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
-                completion(false)
-            }))
-            alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { action in
-                completion(false)
-            }))
-            viewController.present(alert, animated: true, completion: nil)
-            break
-        case PHAuthorizationStatus.notDetermined:
-            PHPhotoLibrary.requestAuthorization { (allowed) in
-                DispatchQueue.main.async {
-                    if allowed == PHAuthorizationStatus.authorized {
-                        completion(true)
-                    } else {
-                        completion(false)
-                    }
-                }
-            }
-            break
-        default:
-            break
-        }
-    }
-    
-    func askLocationManagerPermission(viewController: UIViewController, completion: @escaping (_ hasPermissions: Bool)->()) {
-        
-    }
 }