【问题标题】:Counter on Button “Save” [closed]“保存”按钮上的计数器 [关闭]
【发布时间】:2017-07-07 06:58:43
【问题描述】:

大家好,我需要帮助伙计们)...当我按下按钮 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()
    }

【问题讨论】:

  • 这段代码有什么问题?
  • 到底是什么问题?
  • 您的代码对我来说看起来正确吗?有什么错误吗?

标签: swift button save counter payment


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多