“保存”按钮上的计数器

Counter on Button “Save”

大家好,我需要帮助)...我想制作一个带有计数器的按钮 "snapShotButton",当我按下按钮 3 次时,我想在写入 "you need to pay for use this app" 的地方发出警报。当我按下 "ok" 时,他将使用 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 中,并在每次应用启动后检索它。付款发生后,您可以完全跳过计数器递减。