CNLiveConfigManager.swift 4.18 KB
//
//  CNLiveConfigManager.swift
//  metaCode
//
//  Created by open on 2023/6/5.
//

import Foundation

class ConfigManager : NSObject {
    
    static let shared = ConfigManager()
    
    public var show_update:Bool = true//可以进行显示更新
    public var keyboardDisplayHeight : CGFloat = 0
    
    private override init() {
        super.init()
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShowNotification), name: UIResponder.keyboardDidShowNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidChangeFrameNotification), name: UIResponder.keyboardDidChangeFrameNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidHideNotification), name: UIResponder.keyboardDidHideNotification, object: nil)
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidShowNotification, object: nil)
        NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidChangeFrameNotification, object: nil)
        NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardDidHideNotification, object: nil)
    }
    
    override class func copy() -> Any {
        return self
    }
    
    override class func mutableCopy() -> Any {
        return self
    }
    
    @objc private func keyboardDidShowNotification(notification : Notification) {
        let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
        ConfigManager.shared.keyboardDisplayHeight = keyboardValue?.cgRectValue.size.height ?? 0
    }
    @objc private func keyboardDidChangeFrameNotification(notification : Notification) {
        let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue
        ConfigManager.shared.keyboardDisplayHeight = keyboardValue?.cgRectValue.size.height ?? 0
    }
    @objc private func keyboardDidHideNotification(notification : Notification) {
        ConfigManager.shared.keyboardDisplayHeight = 0
    }
}

extension Notification.Name {
    struct StandAuth {
        //认证身份成功通知
        public static let StandAuthNotificationSuccess = Notification.Name("StandAuthNotificationSuccess")
        //认证身份失败通知
        public static let StandAuthNotificationUnSuccess = Notification.Name("StandAuthNotificationUnSuccess")
        //认证身份排序通知
        public static let StandAuthSortNotificationResult = Notification.Name("StandAuthSortNotificationResult")
    }
    struct NetworkStatus {
        //无网状态通知
        public static let CNLiveNetworkStatusNotificationNotReachable = Notification.Name("CNLiveNetworkStatusNotificationNotReachable")
        //网络未知状态通知
        public static let CNLiveNetworkStatusNotificationUnknown = Notification.Name("CNLiveNetworkStatusNotificationUnknown")
        //蜂窝数据状态通知
        public static let CNLiveNetworkStatusNotificationReachableViaWWAN = Notification.Name("CNLiveNetworkStatusNotificationReachableViaWWAN")
        //WIFI状态通知
        public static let CNLiveNetworkStatusNotificationReachableViaWiFi = Notification.Name("CNLiveNetworkStatusNotificationReachableViaWiFi")
    }
    struct ShopOrderStatue {
        //修改发货成功通知
        public static let CNLiveShopOrderEditExpressNotification = Notification.Name("CNLiveShopOrderEditExpressNotification")
        //发货成功通知
        public static let CNLiveShopOrderSendExpressNotification = Notification.Name("CNLiveShopOrderSendExpressNotification")
    }
    struct ShopGoodsManage {
        //新增商品通知
        public static let kDSGoodsManageAddNotification = Notification.Name("kDSGoodsManageAddNotification")
        //编辑商品通知
        public static let kDSGoodsManageEditNotification = Notification.Name("kDSGoodsManageEditNotification")
        //删除商品通知
        public static let kDSGoodsManageDeleteNotification = Notification.Name("kDSGoodsManageDeleteNotification")
        //搜索确认处理
        public static let kDSSelectGoodsNotification = Notification.Name("kDSSelectGoodsNotification")
    }
}