|
@@ -58,7 +58,6 @@ public extension Notification.Name {
|
|
|
static let kPurchaseDidChanged = Self.init("kPurchaseDidChanged")
|
|
|
}
|
|
|
|
|
|
-private let kFreeNumKey = "kFreeNumKey"
|
|
|
private let kPremiumExpiredInfoKey = "premiumExpiredInfoKey"
|
|
|
|
|
|
|
|
@@ -69,17 +68,10 @@ public class PurchaseManager: NSObject {
|
|
|
@objc public static let `default` = PurchaseManager()
|
|
|
|
|
|
//苹果共享密钥
|
|
|
- private let AppleSharedKey:String = "4ed5151881304025bfee0295ee459422"
|
|
|
+ public var AppleSharedKey:String = ""
|
|
|
|
|
|
//商品信息
|
|
|
- public lazy var purchaseProducts:[PurchaseProduct] = {
|
|
|
- return [
|
|
|
- PurchaseProduct(productId: "01", period:.month),
|
|
|
-// PurchaseProduct(productId: "102", period:.year),
|
|
|
-// PurchaseProduct(productId: "103", period:.week),
|
|
|
- //PurchaseProduct(productId: "003", period: .lifetime),
|
|
|
- ]
|
|
|
- }()
|
|
|
+ public lazy var purchaseProducts:[PurchaseProduct] = []
|
|
|
|
|
|
struct Config {
|
|
|
static let verifyUrl = "https://buy.itunes.apple.com/verifyReceipt"
|
|
@@ -93,9 +85,6 @@ public class PurchaseManager: NSObject {
|
|
|
// 会员信息
|
|
|
var vipInformation: [String: Any] = [:]
|
|
|
|
|
|
- // 免费使用会员的次数
|
|
|
- var freeDict:[String:Int] = [:]
|
|
|
-
|
|
|
//原始订单交易id dict
|
|
|
var originalTransactionIdentifierDict:[String:String] = [:]
|
|
|
|
|
@@ -107,8 +96,6 @@ public class PurchaseManager: NSObject {
|
|
|
if let info = UserDefaults.standard.object(forKey: kPremiumExpiredInfoKey) as? [String: Any] {
|
|
|
vipInformation = info
|
|
|
}
|
|
|
-
|
|
|
- initializeForFree()
|
|
|
}
|
|
|
|
|
|
public var expiredDate: Date? {
|
|
@@ -541,74 +528,6 @@ public extension PurchaseManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-/// 免费生成图片次数
|
|
|
-extension PurchaseManager {
|
|
|
- /// 使用一次免费次数
|
|
|
- func useOnceForFree(type:VipFreeNumType){
|
|
|
-
|
|
|
- if isVip {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- var freeNum = freeDict[type.rawValue] ?? 0
|
|
|
- if freeNum > 0 {
|
|
|
- freeNum-=1
|
|
|
- }
|
|
|
-
|
|
|
- if freeNum < 0 {
|
|
|
- freeNum = 0
|
|
|
- }
|
|
|
-
|
|
|
- freeDict[type.rawValue] = freeNum
|
|
|
- saveForFree()
|
|
|
- }
|
|
|
-
|
|
|
- func freeNum(type:VipFreeNumType) -> Int{
|
|
|
- let freeNum = freeDict[type.rawValue] ?? 0
|
|
|
- return freeNum
|
|
|
- }
|
|
|
-
|
|
|
- func saveForFree(){
|
|
|
- UserDefaults.standard.set(freeDict, forKey: kFreeNumKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
- }
|
|
|
-
|
|
|
- func initializeForFree(){
|
|
|
- if let dict = UserDefaults.standard.dictionary(forKey: kFreeNumKey) as? [String:Int]{
|
|
|
- freeDict = dict
|
|
|
- }else{
|
|
|
- freeDict = [
|
|
|
- VipFreeNumType.ringtones.rawValue:1,
|
|
|
- VipFreeNumType.posetr.rawValue:1,
|
|
|
- VipFreeNumType.photo.rawValue:1
|
|
|
- ]
|
|
|
- saveForFree()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// 免费次数是否可用
|
|
|
- func freeNumAvailable(type:VipFreeNumType) -> Bool{
|
|
|
- if isVip == true {
|
|
|
- return true
|
|
|
- }else{
|
|
|
- if let freeNum = freeDict[type.rawValue],freeNum > 0 {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
- /// 是否展示生成类的会员图标
|
|
|
- func generateVipShow(type:VipFreeNumType) -> Bool{
|
|
|
- if isVip == false, freeNum(type: type) > 0 {
|
|
|
- return false
|
|
|
- }
|
|
|
- return true
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
/*
|
|
|
|
|
|
首先,创建SKProductsRequest对象并使用init(productIdentifiers:)初始化,传入要查询的产品标识符。
|