Files
OrderScheduling/OrderScheduling/Global/GroupData/GroupData.swift
DDIsFriend c853b73127 update
2023-09-07 17:09:41 +08:00

117 lines
4.0 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_title_key] == pushNoti_newOrder_key {
return true
}
if let string = parserAlertToString(userInfo: userInfo), string.contains(pushNoti_newOrder_key) == true {
return true
}
}
return false
}
//
func isAppointmentPushNotification(userInfo:[AnyHashable:Any]?) -> Bool {
if let userInfo {
if let dict = parserAlertToDictionary(userInfo: userInfo), dict[pushNoti_title_key] == pushNoti_appointmentOrder_key {
return true
}
if let string = parserAlertToString(userInfo: userInfo), string.contains(pushNoti_appointmentOrder_key) == true {
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
}
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 {
return (groudUserDefault?.object(forKey: newMessageSound_key) as? Bool) ?? 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)
}
}