按钮"保存"上的计数器



大家好,我需要帮助(...当我按下按钮 3 次时,我想用计数器制作一个按钮"snapShotButton",我想在写"您需要付费才能使用此应用程序"的地方发出警报。当我按"确定"时,他将使用 MKStoreKit 付款......我有MKStoreKit,我的应用程序是视频编辑器...感谢您的帮助最好的问候!!

func addButtons() {
let snapShotButton = UIButton(type: .system)
snapShotButton.setImage(#imageLiteral(resourceName: "snapShot").withRenderingMode(.alwaysOriginal), for: .normal)
snapShotButton.translatesAutoresizingMaskIntoConstraints = false
bottomTabBar.addSubview(snapShotButton)
snapShotButton.centerYAnchor.constraint(equalTo: bottomTabBar.centerYAnchor).isActive = true
snapShotButton.centerXAnchor.constraint(equalTo: bottomTabBar.centerXAnchor).isActive = true
snapShotButton.heightAnchor.constraint(equalToConstant: 32).isActive = true
snapShotButton.widthAnchor.constraint(equalToConstant: 32).isActive = true
snapShotButton.addTarget(self, action: #selector(snapShotButtonTapped), for: .touchUpInside)
snapShotButton.addTarget(self, action: #selector(counterAction), for: .touchUpInside)
}
func counterAction(sender:UIButton){

counter -= 1
print(counter)

if counter == 0 {
MKStoreKit.shared().initiatePaymentRequestForProduct(withIdentifier: "com.steinlogic.iapdemo.quarterly")
}
}


func snapShotButtonTapped() {
pauseVideo()
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: self.videoURL)
}) { saved, error in
if saved {
DispatchQueue.main.async { _ in
self.dismiss(animated: true, completion: nil)
}
}
else {
self.alertErrors()
}
}
//alertNotAvailable()
}

应将计数器的值保存在UserDefaults中,并在每次应用启动后检索它。付款发生后,您可以完全跳过计数器递减。

最新更新