0
因此,我正在實施應用程序內購買到我的應用程序,我正在觀看Jared Davidson的教程如何做到這一點(偉大的教程)但是有一個問題,這是6個月大。我還沒有完成它,但是我在設置警報時遇到了一些錯誤。在'SKError.Code'類型中找不到'Enum case'failed''
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 。代碼
「枚舉案‘noProductIdentifier’型找不到‘SKError.Code’
我知道我得到這些錯誤,因爲他們更新它或東西,有新的情況,但我不是S如何將它們轉換成像哪一個去哪?
我很抱歉,我現在真的很困惑!所有幫助非常感謝!