Files
OrderScheduling/OrderScheduling/Global/GroupData/GroupData.swift
2025-06-25 13:19:31 +08:00

133 lines
4.3 KiB
Swift

//
// GroupData.swift
// OrderScheduling
//
// Created by on 2023/8/30.
//
import Foundation
public let GROUP = GroupData.default
open class GroupData {
public static let `default` = GroupData()
let groudUserDefault = UserDefaults(suiteName: GROUPID)
//
func parserAlertToDictionary(userInfo:[AnyHashable:Any]?) -> Dictionary<String,String>? {
let aps = userInfo?[pushNoti_aps_key] as? [String:Any]
if let data = (aps?[pushNoti_alert_key] as? String)?.data(using: .utf8) {
let dict = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: String]
return dict
}
return nil
}
func parserAlertToString(userInfo:[AnyHashable:Any]?) -> String? {
let aps = userInfo?[pushNoti_aps_key] as? [String:Any]
let string = aps?[pushNoti_alert_key] as? String
return string
}
//
func isOrderPushNotification(userInfo:[AnyHashable:Any]?) -> Bool {
if let userInfo {
if let dict = parserAlertToDictionary(userInfo: userInfo), dict[pushNoti_pushType_key] == "1" {
return true
}
}
return false
}
//
func isCancelOrderPushNotification(userInfo:[AnyHashable:Any]?) -> Bool {
if let userInfo {
if let dict = parserAlertToDictionary(userInfo: userInfo), dict[pushNoti_pushType_key] == "8" {
return true
}
}
return false
}
//
func isReportIndexPushNotification(userInfo:[AnyHashable:Any]?) -> Bool {
if let userInfo {
if let dict = parserAlertToDictionary(userInfo: userInfo), dict[pushNoti_pushType_key] == "10" {
return true
}
}
return false
}
//
func parserBroadcastToString(userInfo:[AnyHashable:Any]?) -> String? {
if let broadcastKeywords = (userInfo?[pushNoti_broadcastKeywords_key] as? String),broadcastKeywords.isEmpty == false {
return broadcastKeywords
}
return nil
}
// 广
func isBroadcastPushNotification(userInfo:[AnyHashable:Any]?) -> Bool {
if let broadcastKeywords = (userInfo?[pushNoti_broadcastKeywords_key] as? String),broadcastKeywords.isEmpty == false {
return true
}
return false
}
//
func isShowPopPushNotification(userInfo:[AnyHashable:Any]?) -> Bool {
if let isShowPop = (userInfo?[pushNoti_isShowPop_key] as? Bool),isShowPop == true {
return true
}
if let isShowPop = (userInfo?[pushNoti_isShowPop_key] as? String),isShowPop == "true" {
return true
}
return false
}
//
public var bestAttemptContentUserInfo : [AnyHashable:Any]? {
return groudUserDefault?.object(forKey: bestAttemptContentUserInfo_key) as? [AnyHashable:Any]
}
func setBestAttemptContentUserInfo(bestAttemptContentUserInfo:[AnyHashable:Any]?) {
groudUserDefault?.set(bestAttemptContentUserInfo, forKey: bestAttemptContentUserInfo_key)
}
//
public var newMessageSound : Bool {
if let value = groudUserDefault?.object(forKey: newMessageSound_key) as? Bool {
return value
}
///
if #available(iOS 17.0, *) {
return false
}
return true
}
func setNewMessageSound(newMessageSound:Bool?) {
groudUserDefault?.set(newMessageSound, forKey: newMessageSound_key)
}
// //
// public var newMessageAlert : Bool {
// return (groudUserDefault?.object(forKey: newMessageAlert_key) as? Bool) ?? true
// }
//
// func setNewMessageAlert(newMessageAlert:Bool?) {
// groudUserDefault?.set(newMessageAlert, forKey: newMessageAlert_key)
// }
func clear() {
// GROUP.setNewMessageAlert(newMessageAlert: nil)
GROUP.setNewMessageSound(newMessageSound: nil)
GROUP.setBestAttemptContentUserInfo(bestAttemptContentUserInfo: nil)
}
}