[英]Sharing CocoaPod using UIApplication.shared between iOS Extension and app
[英]Is there a way to add `if (iOSApplicationExtension)` condition for `UIApplication.shared`
我正在嘗試找到一種方法來添加檢查條件是框架(不是主應用程序)中的擴展目標。 是否可以依靠#available(iOSApplicationExtension, *)
進行一些參數調整?
@objc public extension UIView {
var isAccessibilityCategory: Bool {
if #available(iOSApplicationExtension, *) {
return self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory
} else {
return UIApplication.shared.preferredContentSizeCategory.isAccessibilityCategory
}
}
}
如何檢測代碼是否在主應用程序或應用程序擴展目標中運行? - 不起作用,因為框架不知道擴展目標
為了解決這個問題,我用我創建的所有應用程序創建了一個枚舉器,當用戶啟動應用程序時,我檢查我所在的應用程序的包標識符並將其保存在 appManager 中,因此在我可以執行一些更改后應用程序類型也在框架中。
這是我的枚舉:
public enum MyApp: Int, CaseIterable {
case sysReserved = 0
case app1 = 1
public var applicationId : [String] {
switch self {
case .sysReserved:
return [""]
case .parametersEditor:
return ["com.team.app1"]
}
}
}
這是我的 AppManager
class AppManager: UIApplication {
var CURRENT_APP: MyApp = .sysReserved
override init() {
super.init()
getCurrentApplicationInfo()
}
internal func getCurrentApplicationInfo() {
CURRENT_VERSION_NUM = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
CURRENT_BUILD_NUM = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as! String
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") as! String
CURRENT_APP = .sysReserved
for app in Application.allCases {
if app.applicationId.contains(appName) {
CURRENT_APP = app
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.