|
@@ -38,27 +38,17 @@ class TSPurchaseBusiness {
|
|
|
}
|
|
|
return time
|
|
|
}
|
|
|
-
|
|
|
- public var isOverTotalTimes: Bool {
|
|
|
- if isVip {
|
|
|
- loadTotalUse()
|
|
|
- return totalUsedTimes >= vipType.freeNumber
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
/// 使用一次免费次数
|
|
|
func useOnceForFree(type:VipFreeNumType){
|
|
|
- /// 总使用次数
|
|
|
if isVip {
|
|
|
+ saveForVipFreeNum(type: type)
|
|
|
saveForDayGeneratedNum(type: type)
|
|
|
saveForVipGeneratedNum(type: type)
|
|
|
}
|
|
|
-
|
|
|
- if isVip {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ func saveForVipFreeNum(type: VipFreeNumType){
|
|
|
var freeDict = getFreeDict()
|
|
|
var freeNum = freeDict[type.rawValue] ?? 0
|
|
|
if freeNum > 0 {
|
|
@@ -70,8 +60,7 @@ class TSPurchaseBusiness {
|
|
|
}
|
|
|
|
|
|
freeDict[type.rawValue] = freeNum
|
|
|
- UserDefaults.standard.set(freeDict, forKey: kFreeNumKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
+ saveForUserKeychain(data: freeDict,key: kFreeNumKey)
|
|
|
|
|
|
NotificationCenter.default.post(name: .kVipFreeNumChanged, object: nil, userInfo: ["VipFreeNumType": type])
|
|
|
}
|
|
@@ -81,17 +70,28 @@ class TSPurchaseBusiness {
|
|
|
return freeNum
|
|
|
}
|
|
|
|
|
|
- func loadTotalUse() {
|
|
|
- // 当天没记录,设置默认次数
|
|
|
- guard let dict = UserDefaults.standard.dictionary(forKey: kTotalUseNumKey),
|
|
|
- dict.safeString(forKey: "date") == Date().dateDayString else {
|
|
|
- totalUsedTimes = 0
|
|
|
- return
|
|
|
+ /// 免费次数是否可用
|
|
|
+ func freeNumAvailable(type:VipFreeNumType) -> Bool{
|
|
|
+ if isVip == true {
|
|
|
+ return true
|
|
|
+ }else{
|
|
|
+ if let freeNum = getFreeDict()[type.rawValue],freeNum > 0 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
}
|
|
|
- // 有记录,设置已经使用次数
|
|
|
- totalUsedTimes = dict.safeInt(forKey: "times")
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
+ /// 是否展示生成类的会员图标
|
|
|
+ func generateVipShow(type:VipFreeNumType) -> Bool{
|
|
|
+ if isVip == false, freeNum(type: type) > 0 {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+extension TSPurchaseBusiness{
|
|
|
func initializeForFree(){
|
|
|
|
|
|
if let jsonString = KeychainManager.load(forKey: kFreeNumKey, type: String.self),
|
|
@@ -129,35 +129,23 @@ class TSPurchaseBusiness {
|
|
|
VipFreeNumType.generalVideo.rawValue:1,
|
|
|
VipFreeNumType.generalRemoveBg.rawValue:1
|
|
|
]
|
|
|
- UserDefaults.standard.set(dict, forKey: kFreeNumKey)
|
|
|
- UserDefaults.standard.synchronize()
|
|
|
return dict
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /// 免费次数是否可用
|
|
|
- func freeNumAvailable(type:VipFreeNumType) -> Bool{
|
|
|
- if isVip == true {
|
|
|
- return true
|
|
|
- }else{
|
|
|
- if let freeNum = getFreeDict()[type.rawValue],freeNum > 0 {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
|
|
|
- /// 是否展示生成类的会员图标
|
|
|
- func generateVipShow(type:VipFreeNumType) -> Bool{
|
|
|
- if isVip == false, freeNum(type: type) > 0 {
|
|
|
- return false
|
|
|
+ func saveForUserKeychain(data:[String:Any],key:String) {
|
|
|
+ UserDefaults.standard.set(data, forKey: key)
|
|
|
+ UserDefaults.standard.synchronize()
|
|
|
+
|
|
|
+ //保存到钥匙串
|
|
|
+ if let jsonString = data.toJSONString() {
|
|
|
+ KeychainManager.save(jsonString, forKey: key)
|
|
|
+ dePrint("从钥匙串存入了key=\(key),jsonString=\(jsonString)")
|
|
|
}
|
|
|
- return true
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
extension TSPurchaseBusiness{
|
|
|
-
|
|
|
-
|
|
|
func launchPrchase() {
|
|
|
PurchaseManager.default.password = "155c8104e2b041c0abae43ace199124c"
|
|
|
PurchaseManager.default.purchaseProducts = [
|
|
@@ -168,9 +156,7 @@ extension TSPurchaseBusiness{
|
|
|
]
|
|
|
|
|
|
PurchaseManager.default.requestProducts()
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
extension TSPurchaseBusiness{
|