From 48f996f78ab8e5ff254037e4de451b80709f9a72 Mon Sep 17 00:00:00 2001 From: Nikolay Derkach Date: Thu, 18 Apr 2019 15:46:21 +0100 Subject: [PATCH] use app extension safe APIs --- Example/QRCodeReader.swift.xcodeproj/project.pbxproj | 2 ++ Sources/QRCodeReaderView.swift | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Example/QRCodeReader.swift.xcodeproj/project.pbxproj b/Example/QRCodeReader.swift.xcodeproj/project.pbxproj index 17b4373..0294fc6 100644 --- a/Example/QRCodeReader.swift.xcodeproj/project.pbxproj +++ b/Example/QRCodeReader.swift.xcodeproj/project.pbxproj @@ -642,6 +642,7 @@ CE8FFEED1BAB4E8000D43F38 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEBUG_INFORMATION_FORMAT = dwarf; @@ -666,6 +667,7 @@ CE8FFEEE1BAB4E8000D43F38 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; diff --git a/Sources/QRCodeReaderView.swift b/Sources/QRCodeReaderView.swift index 462b1a0..1c72023 100644 --- a/Sources/QRCodeReaderView.swift +++ b/Sources/QRCodeReaderView.swift @@ -154,8 +154,7 @@ final public class QRCodeReaderView: UIView, QRCodeReaderDisplayable { overlayView?.setNeedsDisplay() - if let connection = reader?.previewLayer.connection, connection.isVideoOrientationSupported { - let application = UIApplication.shared + if let connection = reader?.previewLayer.connection, connection.isVideoOrientationSupported, let application = QRCodeReaderView.sharedApplication { let orientation = UIDevice.current.orientation let supportedInterfaceOrientations = application.supportedInterfaceOrientations(for: application.keyWindow) @@ -165,6 +164,11 @@ final public class QRCodeReaderView: UIView, QRCodeReaderDisplayable { // MARK: - Convenience Methods + private class var sharedApplication: UIApplication? { + let selector = NSSelectorFromString("sharedApplication") + return UIApplication.perform(selector)?.takeRetainedValue() as? UIApplication + } + private func addComponents() { #if swift(>=4.2) let notificationName = UIDevice.orientationDidChangeNotification