From b1bac6de2b211e2d23f2a2ead0e04f0d372b034b Mon Sep 17 00:00:00 2001 From: Marvin <93428739@qq.com> Date: Mon, 24 Jun 2024 16:29:45 +0800 Subject: [PATCH] add LCAppReviewManager --- LCToolsKit.podspec | 7 +- .../LCAppReviewManager.swift | 69 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Sources/LCToolsKit/LCAppReviewManager/LCAppReviewManager.swift diff --git a/LCToolsKit.podspec b/LCToolsKit.podspec index b77061f..7d1ffdd 100644 --- a/LCToolsKit.podspec +++ b/LCToolsKit.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |spec| # spec.name = "LCToolsKit" - spec.version = "1.0.1" + spec.version = "1.0.2" spec.summary = "LCToolsKit is a commonly used tool framework in macOS development" # This description is used to generate tags and improve search results. @@ -134,6 +134,11 @@ Pod::Spec.new do |spec| end + spec.subspec 'LCAppReviewManager' do |ss| + ss.source_files = 'Sources/LCToolsKit/LCAppReviewManager/*.swift' + end + + diff --git a/Sources/LCToolsKit/LCAppReviewManager/LCAppReviewManager.swift b/Sources/LCToolsKit/LCAppReviewManager/LCAppReviewManager.swift new file mode 100644 index 0000000..9599fb9 --- /dev/null +++ b/Sources/LCToolsKit/LCAppReviewManager/LCAppReviewManager.swift @@ -0,0 +1,69 @@ +// +// LCAppReviewManager.swift +// LCAppReviewManager +// +// Created by DevLiuSir on 2021/6/24. +// + +import Foundation + + +/// 应用审核管理器,负责处理应用的审核状态和反盗版检查。 +public class LCAppReviewManager { + + /// 反盗版,判断`审核`是否`通过` + /// - Returns: 审核是否通过 + public class func antiPiracy() -> Bool { + // 获取应用的可执行文件路径 + guard let filePath = Bundle.main.executablePath else { return false } + + do { + // 获取指定文件路径的属性 + let attributes = try FileManager.default.attributesOfItem(atPath: filePath) + // 从文件属性中获取所有者账户 ID + guard let accountID = attributes[.ownerAccountID] as? NSNumber else { return false } + + if accountID.intValue == 501 { // // 如果所有者账户 ID 为 501: 审核中 + print("501") + return false + // 如果所有者账户 ID 为 0 + } else if accountID.intValue == 0 { // 如果所有者账户 ID 为 0: 审核通过 + // 返回 true + return true + } + } catch { + // 如果出现错误,打印错误信息 + print("Error: \(error)") + } + + // 如果所有者账户 ID 既不是 501,也不是 0,返回 false + return false + } + + + + /// 检查`应用`是否在 `Apple 审核中` + /// - Returns: 如果应用处于审核中,则返回 true;否则返回 false + public class func isAppleReview() -> Bool { + // 获取应用的 App Store 购买凭证路径 《票据》 + guard let receiptURL = Bundle.main.appStoreReceiptURL, + // 检查凭证文件是否存在, 如果凭证文件不存在,表示不是来自 App Store 下载的应用 + FileManager.default.fileExists(atPath: receiptURL.path) else { + return false + } + + // 如果凭证文件存在,表示是来自 App Store 下载的应用 + if let execPath = Bundle.main.executablePath, + // 获取可执行文件的属性信息 + let attrInfo = try? FileManager.default.attributesOfItem(atPath: execPath), + // 获取所有者账户 ID + let ownerAccountID = attrInfo[.ownerAccountID] as? NSNumber, + // 检查所有者账户 ID 是否为 501,即是否处于审核中 + ownerAccountID.intValue == 501 { // 如果所有者账户 ID 为 501,表示应用处于审核中 + return true + } else { // 如果所有者账户 ID 不为 501,表示应用已发布到 App Store + return false + } + } + +}