|
@@ -18,37 +18,37 @@ import RealmSwift
|
|
|
import Toast_Swift
|
|
|
import NXFramework_Swift
|
|
|
/// Home文件地址
|
|
|
-let homeDirectory = NSHomeDirectory()
|
|
|
+public let homeDirectory = NSHomeDirectory()
|
|
|
/// docdocumens文件地址
|
|
|
-let documensDirectory = homeDirectory + "/Documents"
|
|
|
+public let documensDirectory = homeDirectory + "/Documents"
|
|
|
/// library文件地址
|
|
|
-let libraryDirectory = homeDirectory + "/Library"
|
|
|
+public let libraryDirectory = homeDirectory + "/Library"
|
|
|
|
|
|
/// 本地存储资源地址
|
|
|
-let resourceDirectory = documensDirectory + "/Resource"
|
|
|
+public let resourceDirectory = documensDirectory + "/Resource"
|
|
|
/// 播放视频缓冲本地沙河目录
|
|
|
-let videoCacheDirectory = resourceDirectory + "/VideoCache"
|
|
|
+public let videoCacheDirectory = resourceDirectory + "/VideoCache"
|
|
|
/// 相册视频导出到本地沙河目录
|
|
|
-let photoLibraryDirectory = resourceDirectory + "/PhotoLibrary/"
|
|
|
+public let photoLibraryDirectory = resourceDirectory + "/PhotoLibrary/"
|
|
|
/// 背景音乐导出到本地沙河目录
|
|
|
-let bgMusicDirectory = resourceDirectory + "/BGMusic/"
|
|
|
+public let bgMusicDirectory = resourceDirectory + "/BGMusic/"
|
|
|
/// 网络视频素材下载到本地沙河目录
|
|
|
-let downloadDirectory = resourceDirectory + "/Download/"
|
|
|
+public let downloadDirectory = resourceDirectory + "/Download/"
|
|
|
/// 网络图片、GIF 素材下载到本地沙河目录
|
|
|
-let downloadImagesDirectory = resourceDirectory + "/DownloadImages/"
|
|
|
+public let downloadImagesDirectory = resourceDirectory + "/DownloadImages/"
|
|
|
/// 临时缓存本地沙河目录地址
|
|
|
-let tempDirectory = resourceDirectory + "/Temp/"
|
|
|
+public let tempDirectory = resourceDirectory + "/Temp/"
|
|
|
/// 导出声音的本地沙盒目录v
|
|
|
-let exportAudiosDirectory = resourceDirectory + "/ExportAudios/"
|
|
|
+public let exportAudiosDirectory = resourceDirectory + "/ExportAudios/"
|
|
|
/// 导出合成视频的本地沙盒目录
|
|
|
-let exportVideosDirectory = resourceDirectory + "/ExportVideos/"
|
|
|
+public let exportVideosDirectory = resourceDirectory + "/ExportVideos/"
|
|
|
// 版本构建号
|
|
|
-let versionCode = "\(Bundle.main.infoDictionary?["CFBundleVersion"] ?? "1")"
|
|
|
+public let versionCode = "\(Bundle.main.infoDictionary?["CFBundleVersion"] ?? "1")"
|
|
|
// 版本号
|
|
|
-let versionName = "\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "1.0.0")"
|
|
|
+public let versionName = "\(Bundle.main.infoDictionary?["CFBundleShortVersionString"] ?? "1.0.0")"
|
|
|
/// 创建目录文件
|
|
|
/// - Returns: <#description#>
|
|
|
-func createDirectory(path: String) {
|
|
|
+public func createDirectory(path: String) {
|
|
|
let fileManager = FileManager.default
|
|
|
if !fileManager.fileExists(atPath: path) {
|
|
|
try? fileManager.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
|
|
@@ -57,7 +57,7 @@ func createDirectory(path: String) {
|
|
|
|
|
|
/// 判断文件夹是否存在
|
|
|
/// - Parameter dicPath:文件夹 目录
|
|
|
-func directoryIsExists(dicPath: String) -> Bool {
|
|
|
+public func directoryIsExists(dicPath: String) -> Bool {
|
|
|
BFLog(message: " dir path is: \(dicPath)")
|
|
|
var directoryExists = ObjCBool(false)
|
|
|
let fileExists = FileManager.default.fileExists(atPath: dicPath, isDirectory: &directoryExists)
|
|
@@ -66,7 +66,7 @@ func directoryIsExists(dicPath: String) -> Bool {
|
|
|
|
|
|
/// 判断文件是否存在
|
|
|
/// - Parameter filepath: 文件目录
|
|
|
-func fileIsExists(filePath: String) -> Bool {
|
|
|
+public func fileIsExists(filePath: String) -> Bool {
|
|
|
BFLog(message: "file path is: \(filePath)")
|
|
|
|
|
|
let fileExists = FileManager.default.fileExists(atPath: filePath)
|
|
@@ -76,7 +76,7 @@ func fileIsExists(filePath: String) -> Bool {
|
|
|
/// 创建沙河文件地址
|
|
|
/// - Parameter url: 原地址
|
|
|
/// - Returns: <#description#>
|
|
|
-func createFilePath(url: String) -> Bool {
|
|
|
+public func createFilePath(url: String) -> Bool {
|
|
|
let fileManager = FileManager.default
|
|
|
if !fileManager.fileExists(atPath: url) {
|
|
|
let isFinished = fileManager.createFile(atPath: url, contents: nil, attributes: nil)
|
|
@@ -85,7 +85,7 @@ func createFilePath(url: String) -> Bool {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-func cIPHONE_X() -> Bool {
|
|
|
+public func cIPHONE_X() -> Bool {
|
|
|
guard #available(iOS 11.0, *) else {
|
|
|
return false
|
|
|
}
|
|
@@ -98,7 +98,7 @@ func cIPHONE_X() -> Bool {
|
|
|
/// - Parameters:
|
|
|
/// - url: 网络url
|
|
|
/// - mainView: 需要加载的视图
|
|
|
-func netImage(url: String, mainView: Any, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
+public func netImage(url: String, mainView: Any, placeholder: UIImage = UIImage(named: "placehold_image")!) {
|
|
|
// if mainView is UIImageView {
|
|
|
// (mainView as! UIImageView).kf.setImage(with: URL(string: url), placeholder: placeholder, options: url.suffix(5) == ".webp" ? [.processor(WebPProcessor.default), .cacheSerializer(WebPSerializer.default)] : nil, progressBlock: { _, _ in
|
|
|
//
|
|
@@ -113,14 +113,14 @@ func netImage(url: String, mainView: Any, placeholder: UIImage = UIImage(named:
|
|
|
}
|
|
|
|
|
|
/** 获取Kingfisher缓存的图片的data */
|
|
|
-func kf_imageCacheData(originUrl: String) -> Data? {
|
|
|
+public func kf_imageCacheData(originUrl: String) -> Data? {
|
|
|
let diskCachePath = ImageCache.default.cachePath(forKey: originUrl)
|
|
|
let data = try? Data(contentsOf: URL(fileURLWithPath: diskCachePath))
|
|
|
return data
|
|
|
}
|
|
|
|
|
|
/** 获取Kingfisher缓存的图片 */
|
|
|
-func kf_imageCacheImage(originUrl: String) -> UIImage? {
|
|
|
+public func kf_imageCacheImage(originUrl: String) -> UIImage? {
|
|
|
return ImageCache.default.retrieveImageInDiskCache(forKey: originUrl, options: [.cacheOriginalImage])
|
|
|
}
|
|
|
|
|
@@ -137,7 +137,7 @@ public func BFLog<T>(message: T) {
|
|
|
|
|
|
// MARK: 获取公共参数
|
|
|
|
|
|
-func commonParams() -> [String: Any] {
|
|
|
+public func commonParams() -> [String: Any] {
|
|
|
let model = UIDevice.current.model
|
|
|
let systemName = UIDevice.current.systemName
|
|
|
let systemVersion = UIDevice.current.systemVersion
|
|
@@ -181,7 +181,7 @@ func commonParams() -> [String: Any] {
|
|
|
|
|
|
/// 获取网络状态
|
|
|
/// - Returns: <#description#>
|
|
|
-func networkStatus() -> String {
|
|
|
+public func networkStatus() -> String {
|
|
|
let status = NetworkReachabilityManager(host: "www.baidu.com")?.networkReachabilityStatus
|
|
|
var statusStr: String!
|
|
|
|
|
@@ -202,13 +202,13 @@ func networkStatus() -> String {
|
|
|
|
|
|
/// 判断是否有网
|
|
|
/// - Returns: <#description#>
|
|
|
-func isNetConnected() -> Bool {
|
|
|
+public func isNetConnected() -> Bool {
|
|
|
return NetworkReachabilityManager(host: "www.baidu.com")?.networkReachabilityStatus != .notReachable
|
|
|
}
|
|
|
|
|
|
/// 获取ip地址
|
|
|
/// - Returns: <#description#>
|
|
|
-func ipAddress() -> String {
|
|
|
+public func ipAddress() -> String {
|
|
|
var addresses = [String]()
|
|
|
var ifaddr: UnsafeMutablePointer<ifaddrs>?
|
|
|
if getifaddrs(&ifaddr) == 0 {
|
|
@@ -236,7 +236,7 @@ func ipAddress() -> String {
|
|
|
/// 生成唯一ID / 分享跟冷启动
|
|
|
/// - Parameter desc: <#desc description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func getUniqueId(desc: String) -> String {
|
|
|
+public func getUniqueId(desc: String) -> String {
|
|
|
let timeStr: String = "\(Date().timeIntervalSince1970)"
|
|
|
let uuid: String = getMachineCode()
|
|
|
let code: String = "\(arc4random_uniform(1_000_000_000))"
|
|
@@ -247,7 +247,7 @@ func getUniqueId(desc: String) -> String {
|
|
|
|
|
|
// MARK: 字典转字符串
|
|
|
|
|
|
-func dictionaryToJsonString(_ dic: [String: Any]) -> String? {
|
|
|
+public func dictionaryToJsonString(_ dic: [String: Any]) -> String? {
|
|
|
BFLog(message: "dictionaryToJsonString = \(dic)")
|
|
|
if !JSONSerialization.isValidJSONObject(dic) {
|
|
|
return ""
|
|
@@ -263,7 +263,7 @@ func dictionaryToJsonString(_ dic: [String: Any]) -> String? {
|
|
|
|
|
|
// MARK: 字符串转字典
|
|
|
|
|
|
-func jsonStringToDictionary(_ str: String) -> [String: Any]? {
|
|
|
+public func jsonStringToDictionary(_ str: String) -> [String: Any]? {
|
|
|
let data = str.data(using: String.Encoding.utf8)
|
|
|
if data == nil {
|
|
|
return [:]
|
|
@@ -276,7 +276,7 @@ func jsonStringToDictionary(_ str: String) -> [String: Any]? {
|
|
|
|
|
|
// MARK: 字符串转数组
|
|
|
|
|
|
-func jsonStringToArray(_ str: String) -> [[String: String]]? {
|
|
|
+public func jsonStringToArray(_ str: String) -> [[String: String]]? {
|
|
|
let data = str.data(using: String.Encoding.utf8)
|
|
|
if let array = try? JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers) as? [[String: String]] {
|
|
|
return array
|
|
@@ -287,7 +287,7 @@ func jsonStringToArray(_ str: String) -> [[String: String]]? {
|
|
|
/// 数组转为string
|
|
|
/// - Parameter array: <#array description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func arrayToJsonString(_ array: [Any]) -> String {
|
|
|
+public func arrayToJsonString(_ array: [Any]) -> String {
|
|
|
if !JSONSerialization.isValidJSONObject(array) {
|
|
|
BFLog(message: "无法解析String")
|
|
|
return ""
|
|
@@ -300,7 +300,7 @@ func arrayToJsonString(_ array: [Any]) -> String {
|
|
|
/// jsonString转为数组
|
|
|
/// - Parameter jsonString: <#jsonString description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func jsonStringToArray(jsonString: String) -> [Any]? {
|
|
|
+public func jsonStringToArray(jsonString: String) -> [Any]? {
|
|
|
let data = jsonString.data(using: String.Encoding.utf8)
|
|
|
if data == nil {
|
|
|
return nil
|
|
@@ -317,7 +317,7 @@ func jsonStringToArray(jsonString: String) -> [Any]? {
|
|
|
/// - font: <#font description#>
|
|
|
/// - size: <#size description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func sizeWithText(text: String, font: UIFont, size: CGSize) -> CGSize {
|
|
|
+public func sizeWithText(text: String, font: UIFont, size: CGSize) -> CGSize {
|
|
|
let attributes = [NSAttributedString.Key.font: font]
|
|
|
let option = NSStringDrawingOptions.usesLineFragmentOrigin
|
|
|
let rect: CGRect = text.boundingRect(with: size, options: option, attributes: attributes, context: nil)
|
|
@@ -331,7 +331,7 @@ func sizeWithText(text: String, font: UIFont, size: CGSize) -> CGSize {
|
|
|
/// - font: <#font description#>
|
|
|
/// - maxSize: <#maxSize description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func sizeTextFits(attributedText: NSMutableAttributedString?, text: String?, numberOfLines: Int, font: UIFont, maxSize: CGSize) -> CGSize {
|
|
|
+public func sizeTextFits(attributedText: NSMutableAttributedString?, text: String?, numberOfLines: Int, font: UIFont, maxSize: CGSize) -> CGSize {
|
|
|
var newSize: CGSize = CGSize(width: 0, height: 0)
|
|
|
let label = UILabel(frame: CGRect.zero)
|
|
|
label.font = font
|
|
@@ -346,7 +346,7 @@ func sizeTextFits(attributedText: NSMutableAttributedString?, text: String?, num
|
|
|
return newSize
|
|
|
}
|
|
|
|
|
|
-func textNumberOfLines(text: String, font: UIFont, maxSize _: CGSize) -> Int {
|
|
|
+public func textNumberOfLines(text: String, font: UIFont, maxSize _: CGSize) -> Int {
|
|
|
let label = UILabel(frame: CGRect.zero)
|
|
|
label.font = font
|
|
|
label.numberOfLines = 0
|
|
@@ -361,7 +361,7 @@ func textNumberOfLines(text: String, font: UIFont, maxSize _: CGSize) -> Int {
|
|
|
/// - startColor: <#startColor description#>
|
|
|
/// - endColor: <#endColor description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func gradientColor(size: CGSize, endPoint: CGPoint, startColor: UIColor, endColor: UIColor) -> UIColor {
|
|
|
+public func gradientColor(size: CGSize, endPoint: CGPoint, startColor: UIColor, endColor: UIColor) -> UIColor {
|
|
|
let gradientLayer = CAGradientLayer()
|
|
|
gradientLayer.frame = CGRect(origin: CGPoint(), size: size)
|
|
|
gradientLayer.startPoint = CGPoint.zero
|
|
@@ -375,7 +375,7 @@ func gradientColor(size: CGSize, endPoint: CGPoint, startColor: UIColor, endColo
|
|
|
|
|
|
/// 获取设备ID
|
|
|
/// - Returns: <#description#>
|
|
|
-func getMachineCode() -> String {
|
|
|
+public func getMachineCode() -> String {
|
|
|
let userInfo: [String: Any]? = jsonStringToDictionary(UserDefaults.standard.string(forKey: cUserInfoStorageKey) ?? "")
|
|
|
if userInfo != nil && ((userInfo?.keys.contains("isVirtualUser") ?? false) && !(userInfo?["isVirtualUser"] is NSNull) && ((userInfo?["isVirtualUser"] as? Bool) ?? false)) && ((userInfo?.keys.contains("mid") ?? false) && !(userInfo?["mid"] is NSNull)) {
|
|
|
BFLog(message: "虚拟账号mid:\("\(userInfo?["mid"] ?? "")")")
|
|
@@ -396,7 +396,7 @@ func getMachineCode() -> String {
|
|
|
/// - superView: <#superView description#>
|
|
|
/// - msg: <#msg description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func cShowHUB(superView: UIView?, msg: String?) {
|
|
|
+ public func cShowHUB(superView: UIView?, msg: String?) {
|
|
|
DispatchQueue.main.async {
|
|
|
if superView == nil {
|
|
|
if msg == nil {
|
|
@@ -417,7 +417,7 @@ func cShowHUB(superView: UIView?, msg: String?) {
|
|
|
/// 隐藏加载中视图
|
|
|
/// - Parameter superView: <#superView description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func cHiddenHUB(superView: UIView?) {
|
|
|
+public func cHiddenHUB(superView: UIView?) {
|
|
|
DispatchQueue.main.async {
|
|
|
if superView == nil {
|
|
|
UIApplication.shared.keyWindow?.hideAllToasts()
|
|
@@ -432,7 +432,7 @@ func cHiddenHUB(superView: UIView?) {
|
|
|
/// 获取存储值
|
|
|
/// - Parameter key: key description
|
|
|
/// - Returns: description
|
|
|
-func getUserDefaults(key: String) -> Any? {
|
|
|
+public func getUserDefaults(key: String) -> Any? {
|
|
|
return UserDefaults.standard.object(forKey: key)
|
|
|
}
|
|
|
|
|
@@ -441,7 +441,7 @@ func getUserDefaults(key: String) -> Any? {
|
|
|
/// - key: key description
|
|
|
/// - value: value description
|
|
|
/// - Returns: description
|
|
|
-func saveUserDefaults(key: String, value: String) {
|
|
|
+public func saveUserDefaults(key: String, value: String) {
|
|
|
UserDefaults.standard.set(value, forKey: key)
|
|
|
UserDefaults.standard.synchronize()
|
|
|
}
|
|
@@ -450,7 +450,7 @@ func saveUserDefaults(key: String, value: String) {
|
|
|
/// - Parameters:
|
|
|
/// - key: <#key description#>
|
|
|
/// - value: <#value description#>
|
|
|
-func saveUserDefaultsToJson(key: String, value: Any) {
|
|
|
+public func saveUserDefaultsToJson(key: String, value: Any) {
|
|
|
UserDefaults.standard.set(dictionaryToJsonString([key: value, "appVersionCode": versionCode, "versionName": versionName]), forKey: key)
|
|
|
UserDefaults.standard.synchronize()
|
|
|
}
|
|
@@ -458,7 +458,7 @@ func saveUserDefaultsToJson(key: String, value: Any) {
|
|
|
/// 获取数据带版本号
|
|
|
/// - Parameter key: <#key description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func getUserDefaultsForJson(key: String) -> Any? {
|
|
|
+public func getUserDefaultsForJson(key: String) -> Any? {
|
|
|
let jsonStr = UserDefaults.standard.object(forKey: key)
|
|
|
if jsonStr != nil {
|
|
|
return jsonStringToDictionary(jsonStr as! String)?[key]
|
|
@@ -471,7 +471,7 @@ func getUserDefaultsForJson(key: String) -> Any? {
|
|
|
/// - key: key description
|
|
|
/// - value: value description
|
|
|
/// - Returns: description
|
|
|
-func removeUserDefaults(key: String) {
|
|
|
+public func removeUserDefaults(key: String) {
|
|
|
UserDefaults.standard.removeObject(forKey: key)
|
|
|
UserDefaults.standard.synchronize()
|
|
|
}
|
|
@@ -481,7 +481,7 @@ func removeUserDefaults(key: String) {
|
|
|
/// - key: key description
|
|
|
/// - value: value description
|
|
|
/// - Returns: description
|
|
|
-func saveUserDefaults(key: String, value: Any) {
|
|
|
+public func saveUserDefaults(key: String, value: Any) {
|
|
|
UserDefaults.standard.set(value, forKey: key)
|
|
|
UserDefaults.standard.synchronize()
|
|
|
}
|
|
@@ -489,7 +489,7 @@ func saveUserDefaults(key: String, value: Any) {
|
|
|
/// 保存自定义model as NSArray 当 OBJ 是数组时不能使用 Array 要使用 NSArray
|
|
|
/// - Parameter object: <#object description#>
|
|
|
/// - Parameter key: <#key description#>
|
|
|
-func saveCustomObject(customObject object: NSCoding, key: String) {
|
|
|
+public func saveCustomObject(customObject object: NSCoding, key: String) {
|
|
|
let encodedObject = NSKeyedArchiver.archivedData(withRootObject: object)
|
|
|
UserDefaults.standard.set(encodedObject, forKey: key)
|
|
|
UserDefaults.standard.synchronize()
|
|
@@ -498,7 +498,7 @@ func saveCustomObject(customObject object: NSCoding, key: String) {
|
|
|
|
|
|
/// 取自定义model
|
|
|
/// - Parameter key: <#key description#>
|
|
|
-func getCustomObject(forKey key: String) -> AnyObject? {
|
|
|
+public func getCustomObject(forKey key: String) -> AnyObject? {
|
|
|
let decodedObject = UserDefaults.standard.object(forKey: key) as? Data
|
|
|
|
|
|
if decodedObject == nil {
|
|
@@ -520,21 +520,21 @@ func getCustomObject(forKey key: String) -> AnyObject? {
|
|
|
/// - aName: <#aName description#>
|
|
|
/// - anObject: <#anObject description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func addNotification(_ observer: Any, selector aSelectorName: Selector, name aName: String, object anObject: Any?) {
|
|
|
+public func addNotification(_ observer: Any, selector aSelectorName: Selector, name aName: String, object anObject: Any?) {
|
|
|
PQNotification.addObserver(observer, selector: aSelectorName, name: NSNotification.Name(rawValue: aName), object: anObject)
|
|
|
}
|
|
|
|
|
|
/// 发送通知
|
|
|
/// - Parameter aName: <#aName description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func postNotification(name aName: String, userInfo: [AnyHashable: Any]? = nil) {
|
|
|
+public func postNotification(name aName: String, userInfo: [AnyHashable: Any]? = nil) {
|
|
|
PQNotification.post(name: NSNotification.Name(aName), object: nil, userInfo: userInfo)
|
|
|
}
|
|
|
|
|
|
/// 获取是否打开推送
|
|
|
/// - Parameter completeHander: <#completeHander description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func pushNotificationIsOpen(completeHander: ((_ isOpen: Bool) -> Void)?) {
|
|
|
+public func pushNotificationIsOpen(completeHander: ((_ isOpen: Bool) -> Void)?) {
|
|
|
if #available(iOS 10.0, *) {
|
|
|
UNUserNotificationCenter.current().getNotificationSettings { setttings in
|
|
|
completeHander!(setttings.authorizationStatus == .authorized)
|
|
@@ -547,7 +547,7 @@ func pushNotificationIsOpen(completeHander: ((_ isOpen: Bool) -> Void)?) {
|
|
|
/// 发送上传本地推送
|
|
|
/// - Parameter isSuccess: 是否上传成功
|
|
|
/// - Returns: <#description#>
|
|
|
-func sendUploadNotification(isSuccess: Bool) {
|
|
|
+public func sendUploadNotification(isSuccess: Bool) {
|
|
|
let title: String = isSuccess ? "上传完成了!" : "上传失败了!"
|
|
|
let body: String = isSuccess ? "请点击发布,完成上传。否则,您的视频可能丢失" : "快来看看怎么了?"
|
|
|
sendLocalNotification(title: title, body: body)
|
|
@@ -558,7 +558,7 @@ func sendUploadNotification(isSuccess: Bool) {
|
|
|
/// - title: 标题
|
|
|
/// - body: 内容
|
|
|
/// - Returns: <#description#>
|
|
|
-func sendLocalNotification(title: String, body: String) {
|
|
|
+public func sendLocalNotification(title: String, body: String) {
|
|
|
// 设置推送内容
|
|
|
if #available(iOS 10.0, *) {
|
|
|
let content = UNMutableNotificationContent()
|
|
@@ -591,7 +591,7 @@ func sendLocalNotification(title: String, body: String) {
|
|
|
}
|
|
|
|
|
|
/// 打开应用设置
|
|
|
-func openAppSetting() {
|
|
|
+public func openAppSetting() {
|
|
|
if UIApplication.shared.canOpenURL(URL(string: UIApplication.openSettingsURLString)!) {
|
|
|
UIApplication.shared.openURL(URL(string: UIApplication.openSettingsURLString)!)
|
|
|
}
|
|
@@ -600,7 +600,7 @@ func openAppSetting() {
|
|
|
/// dns解析
|
|
|
/// - Parameter hostUrl: speed.piaoquantv.com /
|
|
|
/// - Returns: <#description#>
|
|
|
-func parseDNS(hostUrl: String) -> [String: Any]? {
|
|
|
+public func parseDNS(hostUrl: String) -> [String: Any]? {
|
|
|
let host: CFHost? = CFHostCreateWithName(nil, hostUrl as CFString).takeRetainedValue()
|
|
|
let start = CFAbsoluteTimeGetCurrent()
|
|
|
var success: DarwinBoolean = false
|
|
@@ -633,7 +633,7 @@ func parseDNS(hostUrl: String) -> [String: Any]? {
|
|
|
|
|
|
/// 获取当前日期
|
|
|
/// - Returns: <#description#>
|
|
|
-func systemCurrentDate() -> String {
|
|
|
+public func systemCurrentDate() -> String {
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.dateFormat = "YYYY-MM-dd"
|
|
|
return dateFormatter.string(from: Date())
|
|
@@ -642,7 +642,7 @@ func systemCurrentDate() -> String {
|
|
|
/// 时间戳转日期
|
|
|
/// - Parameter timeInterval: <#timeInterval description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func timeIntervalToDateString(timeInterval: TimeInterval) -> String {
|
|
|
+public func timeIntervalToDateString(timeInterval: TimeInterval) -> String {
|
|
|
let date = Date(timeIntervalSince1970: timeInterval)
|
|
|
let dateFormatter = DateFormatter()
|
|
|
dateFormatter.dateFormat = "MM月dd日 HH:mm"
|
|
@@ -652,7 +652,7 @@ func timeIntervalToDateString(timeInterval: TimeInterval) -> String {
|
|
|
/// 判断字符串或者字典是否为空
|
|
|
/// - Parameter object: <#object description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func isEmpty(object: Any?) -> Bool {
|
|
|
+public func isEmpty(object: Any?) -> Bool {
|
|
|
if object == nil {
|
|
|
return true
|
|
|
}
|
|
@@ -665,7 +665,7 @@ func isEmpty(object: Any?) -> Bool {
|
|
|
return false
|
|
|
}
|
|
|
|
|
|
-func isEmptyObject(object: Any?) -> Bool {
|
|
|
+public func isEmptyObject(object: Any?) -> Bool {
|
|
|
if object == nil {
|
|
|
return true
|
|
|
}
|
|
@@ -684,7 +684,7 @@ func isEmptyObject(object: Any?) -> Bool {
|
|
|
/// <#Description#>
|
|
|
/// - Parameter string: <#string description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func isIncludeChineseIn(string: String) -> Bool {
|
|
|
+public func isIncludeChineseIn(string: String) -> Bool {
|
|
|
for (_, value) in string.enumerated() {
|
|
|
if value >= "\u{4E00}", value <= "\u{9FA5}" {
|
|
|
return true
|
|
@@ -698,7 +698,7 @@ func isIncludeChineseIn(string: String) -> Bool {
|
|
|
/// - path: 地址
|
|
|
/// - data: data
|
|
|
/// - Returns: <#description#>
|
|
|
-func contentMD5(path: String? = nil, data _: Data? = nil) -> String? {
|
|
|
+public func contentMD5(path: String? = nil, data _: Data? = nil) -> String? {
|
|
|
if path == nil || (path?.count ?? 0) <= 0 || !FileManager.default.fileExists(atPath: path ?? "") {
|
|
|
BFLog(message: "生成内容md5值:地址错误或者不存在\(String(describing: path))")
|
|
|
return ""
|
|
@@ -760,7 +760,7 @@ func contentMD5(path: String? = nil, data _: Data? = nil) -> String? {
|
|
|
/// - width: <#width description#>
|
|
|
/// - baseWidth: <#baseWidth description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func adapterWidth(width: CGFloat, baseWidth: CGFloat = 375) -> CGFloat {
|
|
|
+public func adapterWidth(width: CGFloat, baseWidth: CGFloat = 375) -> CGFloat {
|
|
|
return width / baseWidth * cScreenWidth
|
|
|
}
|
|
|
|
|
@@ -769,14 +769,14 @@ func adapterWidth(width: CGFloat, baseWidth: CGFloat = 375) -> CGFloat {
|
|
|
/// - height: <#height description#>
|
|
|
/// - baseHeight: <#baseHeight description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func adapterHeight(height: CGFloat, baseHeight: CGFloat = 812) -> CGFloat {
|
|
|
+public func adapterHeight(height: CGFloat, baseHeight: CGFloat = 812) -> CGFloat {
|
|
|
return height / baseHeight * cScreenHeigth
|
|
|
}
|
|
|
|
|
|
/// 检测URL
|
|
|
/// - Parameter url: <#url description#>
|
|
|
/// - Returns: <#description#>
|
|
|
-func isValidURL(url: String?) -> Bool {
|
|
|
+public func isValidURL(url: String?) -> Bool {
|
|
|
if url == nil || (url?.count ?? 0) <= 4 || (!(url?.hasPrefix("http") ?? false) && !(url?.hasPrefix("https") ?? false)) {
|
|
|
return false
|
|
|
}
|
|
@@ -816,7 +816,7 @@ var playGifImages: [UIImage] = {
|
|
|
/// - Parameter image: <#image description#>
|
|
|
/// -
|
|
|
/// - Returns: <#description#>
|
|
|
-func zipImage(image: UIImage?, size: Int) -> Data? {
|
|
|
+public func zipImage(image: UIImage?, size: Int) -> Data? {
|
|
|
var data = image?.pngData()
|
|
|
var dataKBytes = Int(data?.count ?? 0) / 1000
|
|
|
var maxQuality = 0.9
|