From 6b7d7409c4f4b7af52c0c09c8939dd357694e433 Mon Sep 17 00:00:00 2001 From: Emilio Pavia Date: Wed, 16 Sep 2020 15:50:19 +0200 Subject: [PATCH 1/4] Add support for .limited PHPhotoLibrary authorization status --- ScienceJournal/UI/PhotoLibraryDataSource.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ScienceJournal/UI/PhotoLibraryDataSource.swift b/ScienceJournal/UI/PhotoLibraryDataSource.swift index 94870e3b..42f89626 100644 --- a/ScienceJournal/UI/PhotoLibraryDataSource.swift +++ b/ScienceJournal/UI/PhotoLibraryDataSource.swift @@ -93,7 +93,7 @@ class PhotoLibraryDataSource: NSObject, PHPhotoLibraryChangeObserver { let authStatus = PHPhotoLibrary.authorizationStatus() switch authStatus { case .denied, .restricted: return false - case .authorized: return true + case .authorized, .limited: return true case .notDetermined: // Prompt user for the permission to use the camera. PHPhotoLibrary.requestAuthorization({ (status) in @@ -103,6 +103,7 @@ class PhotoLibraryDataSource: NSObject, PHPhotoLibraryChangeObserver { } }) return false + @unknown default: return false } } From 7ff1ba2f087aae2f258e9425a54483cca4eb3954 Mon Sep 17 00:00:00 2001 From: Emilio Pavia Date: Wed, 16 Sep 2020 15:52:02 +0200 Subject: [PATCH 2/4] Convert project to Xcode 12 recommended settings --- ScienceJournal.xcodeproj/project.pbxproj | 6 ++++- .../xcschemes/ScienceJournal.xcscheme | 24 ++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ScienceJournal.xcodeproj/project.pbxproj b/ScienceJournal.xcodeproj/project.pbxproj index 5bdffcc1..c77b996b 100644 --- a/ScienceJournal.xcodeproj/project.pbxproj +++ b/ScienceJournal.xcodeproj/project.pbxproj @@ -3138,7 +3138,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 0940; + LastUpgradeCheck = 1200; ORGANIZATIONNAME = Arduino; TargetAttributes = { 68EBA6D91E20421E0089FF7F = { @@ -4151,6 +4151,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -4319,6 +4320,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -4506,6 +4508,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -4565,6 +4568,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; diff --git a/ScienceJournal.xcodeproj/xcshareddata/xcschemes/ScienceJournal.xcscheme b/ScienceJournal.xcodeproj/xcshareddata/xcschemes/ScienceJournal.xcscheme index 9a955629..d34d57d0 100644 --- a/ScienceJournal.xcodeproj/xcshareddata/xcschemes/ScienceJournal.xcscheme +++ b/ScienceJournal.xcodeproj/xcshareddata/xcschemes/ScienceJournal.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -49,17 +58,6 @@ - - - - - - - - Date: Wed, 16 Sep 2020 15:53:56 +0200 Subject: [PATCH 3/4] Convert project to Base internationalization --- ScienceJournal.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ScienceJournal.xcodeproj/project.pbxproj b/ScienceJournal.xcodeproj/project.pbxproj index c77b996b..64d93e06 100644 --- a/ScienceJournal.xcodeproj/project.pbxproj +++ b/ScienceJournal.xcodeproj/project.pbxproj @@ -3168,10 +3168,9 @@ }; buildConfigurationList = 68EBA6D51E20421E0089FF7F /* Build configuration list for PBXProject "ScienceJournal" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( - English, ar, bg, bs, @@ -3249,6 +3248,7 @@ zh_CN, zh_HK, zh_TW, + Base, ); mainGroup = 68EBA6D11E20421E0089FF7F; productRefGroup = 68EBA6DB1E20421E0089FF7F /* Products */; From c1f77046f21c95f4fbd29665ddc9231d2853ae2d Mon Sep 17 00:00:00 2001 From: Emilio Pavia Date: Wed, 16 Sep 2020 16:44:24 +0200 Subject: [PATCH 4/4] Adopt new PHPhotoLibrary APIs in iOS 14 --- .../UI/PhotoLibraryDataSource.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ScienceJournal/UI/PhotoLibraryDataSource.swift b/ScienceJournal/UI/PhotoLibraryDataSource.swift index 42f89626..80fa8609 100644 --- a/ScienceJournal/UI/PhotoLibraryDataSource.swift +++ b/ScienceJournal/UI/PhotoLibraryDataSource.swift @@ -90,18 +90,29 @@ class PhotoLibraryDataSource: NSObject, PHPhotoLibraryChangeObserver { /// The permissions state of the capturer. var isPhotoLibraryPermissionGranted: Bool { - let authStatus = PHPhotoLibrary.authorizationStatus() + let authStatus: PHAuthorizationStatus + if #available(iOS 14, *) { + authStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite) + } else { + authStatus = PHPhotoLibrary.authorizationStatus() + } switch authStatus { case .denied, .restricted: return false case .authorized, .limited: return true case .notDetermined: - // Prompt user for the permission to use the camera. - PHPhotoLibrary.requestAuthorization({ (status) in + let handler: (PHAuthorizationStatus) -> Void = { status in DispatchQueue.main.sync { let granted = status == .authorized self.delegate?.photoLibraryDataSourcePermissionsDidChange(accessGranted: granted) } - }) + } + + // Prompt user for the permission to use the camera. + if #available(iOS 14, *) { + PHPhotoLibrary.requestAuthorization(for: .readWrite, handler: handler) + } else { + PHPhotoLibrary.requestAuthorization(handler) + } return false @unknown default: return false }