Commit de98cae7 authored by CZ1004's avatar CZ1004

Merge branch 'develop_0409' into homeUpdate

* develop_0409:
  4 -  10
parents 7e531da8 42c0bd8c
...@@ -440,3 +440,23 @@ extension HomeNoAdsViewController : UIScrollViewDelegate { ...@@ -440,3 +440,23 @@ extension HomeNoAdsViewController : UIScrollViewDelegate {
root.present(nav, animated: true) root.present(nav, animated: true)
} }
} }
class BackgroundTaskManager {
static let share = BackgroundTaskManager()
private var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid
func startTask() {
backgroundTaskID = UIApplication.shared.beginBackgroundTask { [weak self] in
self?.endTask() // 超时强制终止
}
}
func endTask() {
guard backgroundTaskID != .invalid else { return }
UIApplication.shared.endBackgroundTask(backgroundTaskID)
backgroundTaskID = .invalid
}
}
...@@ -83,10 +83,15 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs ...@@ -83,10 +83,15 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
} }
func fetchProducts() { func fetchProducts() {
BackgroundTaskManager.share.startTask()
let request = SKProductsRequest(productIdentifiers: Set(productIdentifiers)) let request = SKProductsRequest(productIdentifiers: Set(productIdentifiers))
request.delegate = self request.delegate = self
request.start() request.start()
Print("获取商品信息") Print("获取商品信息")
DispatchQueue.global().asyncAfter(deadline: .now() + 15) {
request.cancel()
BackgroundTaskManager.share.endTask()
}
} }
private var product:[SKProduct?]? private var product:[SKProduct?]?
...@@ -109,10 +114,15 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs ...@@ -109,10 +114,15 @@ class HomePayModel: NSObject ,SKProductsRequestDelegate ,SKPaymentTransactionObs
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: { DispatchQueue.main.asyncAfter(deadline: .now() + 0.2, execute: {
self.product = ps self.product = ps
Print("获取商品信息成功") Print("获取商品信息成功")
BackgroundTaskManager.share.endTask()
self.storeCall(ps) self.storeCall(ps)
}) })
} }
func request(_ request: SKRequest, didFailWithError error: Error) {
BackgroundTaskManager.share.endTask()
}
/** 购买 */ /** 购买 */
func purchase(_ states:PayState = .Subscribe) -> Void { func purchase(_ states:PayState = .Subscribe) -> Void {
guard let p1 = product?.first, guard let p1 = product?.first,
......
...@@ -15,7 +15,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate { ...@@ -15,7 +15,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
case del // 删除 case del // 删除
} }
var Callback:((_ suc:Bool)->Void)? var Callback:((_ suc:Bool)->Void) = { suc in }
var secretType:SecretType = .create { var secretType:SecretType = .create {
didSet{ didSet{
...@@ -43,9 +43,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate { ...@@ -43,9 +43,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
self.navigationController?.popToRootViewController(animated: true) self.navigationController?.popToRootViewController(animated: true)
return return
} }
if Callback != nil { Callback(false)
Callback!(false)
}
super.close(animation: animation) super.close(animation: animation)
} }
...@@ -79,10 +77,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate { ...@@ -79,10 +77,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
self.present(alert, animated: true) self.present(alert, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
alert.dismiss(animated: true) { alert.dismiss(animated: true) {
guard self.Callback != nil else { self.Callback(true)
return
}
self.Callback!(true)
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
} }
...@@ -95,10 +90,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate { ...@@ -95,10 +90,7 @@ class SecretSetViewController: BaseViewController, UITextFieldDelegate {
} }
return return
} }
guard Callback != nil else { Callback(true)
return
}
Callback!(true)
self.navigationController?.popViewController(animated: true) self.navigationController?.popViewController(animated: true)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment