1

Я хочу сделать кнопку «snapShotButton» со счетчиком, когда я нажимаю кнопку 3 раза, я хочу сделать предупреждение, где пишут «вам нужно платить за использование этого приложения». И когда я нажимаю «хорошо», он будет платить с MKStoreKit ... У меня есть MKStoreKit, а мое приложение - Video Editor ...

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()
    }
1
  • 1
    Используйте кнопку "Фрагмент кода" только для кода, который реально может быть выполнен в браузере. Для кусков кода не на JS/HTML/CSS следует использовать блоки кода, форматируемые с помощью отступа в 4 пробела (Ctrl+K). 6 июл 2017 в 14:09

1 ответ 1

0

Используйте UIAlertController, добавьте в вью контроллер метод

func allertMessage(message: String,
                   handler:((_ succes:Bool) -> Swift.Void)? = nil){
    let allertController = UIAlertController(title: "",
                                             message: message,
                                             preferredStyle: UIAlertControllerStyle.alert)
    let actionCancel = UIAlertAction(title: "Pay",
                                     style: UIAlertActionStyle.cancel)
    { (action) in
        if (handler != nil){
            handler!(true)
        }
        allertController.removeFromParentViewController()
    }

    let actionOk = UIAlertAction(title: "No",
                                     style: UIAlertActionStyle.cancel)
    { (action) in
        if (handler != nil){
            handler!(false)
        }
        allertController.removeFromParentViewController()
    }

    allertController.addAction(actionCancel)
    allertController.addAction(actionOk)
    self.present(allertController, animated: true, completion: nil)
}

и в методе каунтера вызывайте

 func counterAction(sender:UIButton){

    counter -= 1
    print(counter)

    if counter == 0 {
        self.allertMessage(message: "Вам нужно платить за использование этого приложения") 
        { (result) in 
            if result {
                MKStoreKit.shared().initiatePaymentRequestForProduct(withIdentifier: "com.steinlogic.iapdemo.quarterly")
            }
        }
    }
}

Будет две кнопки и сообщение, если нажмет "нет" то в result придет false и окно пропадет, если нажмет "да" то перебросите на оплату.

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.