在'SKError.Code'类型中找不到Enum case'failed'

时间:2017-07-04 06:17:21

标签: swift in-app-purchase

所以我正在我的应用程序中实现应用内购买,我正在观看Jared Davidson关于如何做到这一点的教程(很棒的教程)但是有一个问题,它是6个月大。我还没有完成它,但我在设置警报时遇到了一些错误。

extension ViewController {

        func alertWithTitle(title: String, message : String) -> UIAlertController {

            let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
            return alert


    }

        func showAlert(alert : UIAlertController) {
            guard let _ = self.presentedViewController else {
                self.present(alert, animated:  true, completion: nil)
                return
            }


        }
        func alertForProductRetrievalInfo(result : RetrieveResults) -> UIAlertController {
            if let product = result.retrievedProducts.first {
                let priceString = product.localizedPrice!
                return alertWithTitle(title: product.localizedTitle, message: "\(product.localizedDescription) - \(priceString)")
            }
            else if let ivalidProductID = result.invalidProductIDs.first {
                return alertWithTitle(title: "Could not retrieve product info", message: "Invalid product identifier: \(ivalidProductID)")
            }
            else {
                let errorString = result.error?.localizedDescription ?? "Unknown Error. Please Contact Support"
                return alertWithTitle(title: "Could not retreive product info", message: errorString)
            }
        }
        func alertForPurchaseResult(result : PurchaseResult) -> UIAlertController {
            switch result {
            case .success(let product):
                print("Purchase Succesful: \(product.productId)")

                /////////////////////////////////////////////////////////////////////////////////////
                return alertWithTitle(title: "Thank you for your kind donation!", message: "Purchase completed")
            case .error(let error):
                print("Purchase Failed: \(error)")
                switch error.code {
                case .failed(let error):
                    if (error as NSError).domain == SKErrorDomain {
                        return alertWithTitle(title: "Purchase Failed", message: "Check your internet connection or try again later.")
                    }
                    else {
                        return alertWithTitle(title: "Purchase Failed", message: "Unkown Error. Please Contact Support")
                    }
                case .invalidProductID(let productID):
                    return alertWithTitle(title: "Purchase Failed", message: "\(productID) is not a valid product identifier")
                case .noProductIdentifier:
                    return alertWithTitle(title: "Purchase Failed", message: "Product not found")
                case .paymentNotAllowed:
                    return alertWithTitle(title: "Purchase Failed", message: "You are not allowed to make payments")

                }

        }

    }

这些是我得到的错误:

“枚举案例'失败'未找到类型”SKError.Code“
”枚举案例'invalidProductID'未在类型“SKError.Code
中找到

“枚举案例'noProductIdentifier'未在类型”SKError.Code“中找到

我知道我得到了这些错误,因为他们更新了它或者有新的情况,但是我不知道如何将它们转换成哪个跟哪个一起?

我道歉,我现在真的很困惑!非常感谢所有帮助!!

1 个答案:

答案 0 :(得分:1)

教程最近使用的框架(SwiftyStoreKit)changed错误检查API如何工作。更新的应该是:

(setenv "PGPASSWORD" "whatever your password is")