2017-07-04 3 views
0

Je suis donc en train d'implémenter l'achat in-app dans mon application et je regarde le didacticiel de Jared Davidson sur la façon de le faire (excellent tutoriel) Cependant il y a un problème , il a 6 mois. Je ne l'ai pas encore terminé mais j'ai juste rencontré quelques erreurs lors de la configuration des alertes.Enum case 'failed' introuvable dans le type 'SKError.Code'

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") 

       } 

     } 

    } 

Ce sont les erreurs que je reçois:

"Enum cas 'échoué' introuvable dans le type "SKError.Code"
" Enum case 'invalidProductID' introuvable dans le type « SKError .code

« Enum case « noProductIdentifier » introuvable dans le type « SKError.Code »

Je sais que je reçois ces erreurs parce qu'ils mis à jour ou quelque chose et il y a de nouveaux cas, mais je ne suis pas s comment les convertir comme qui va avec qui? Je m'excuse, je suis juste vraiment confus en ce moment! Toute aide est grandement appréciée!!

Répondre

0

Le cadre que le tutoriel utilise (SwiftyStoreKit) récemment changed comment l'API de vérification d'erreur fonctionne. La mise à jour devrait être:

func alertForPurchaseResult(result : PurchaseResult) -> UIAlertController { 
     switch result { 
     case .success(let product): 
      return alertWithTitle(title: "Thank You", message: "Purchase completed") 
     case .error(let error): 
      switch error.code { 
      case .unknown: return alertWithTitle(title: "Purchase Error", message: "Unknown error. Please contact support") 
      case .clientInvalid: return alertWithTitle(title: "Purchase Error", message: "Not allowed to make the payment") 
      case .paymentCancelled: return alertWithTitle(title: "Payment Cancelled", message: "Payment Cancelled") 
      case .paymentInvalid: return alertWithTitle(title: "Purchase Error", message: "The purchase identifier was invalid") 
      case .paymentNotAllowed: return alertWithTitle(title: "Purchase Error", message: "The device is not allowed to make the payment") 
      case .storeProductNotAvailable: return alertWithTitle(title: "Purchase Error", message: "The product is not available in the current storefront") 
      case .cloudServicePermissionDenied: return alertWithTitle(title: "Purchase Error", message: "Access to cloud service information is not allowed") 
      case .cloudServiceNetworkConnectionFailed: return alertWithTitle(title: "Purchase Error", message: "Could not connect to the network") 
      default: return alertWithTitle(title: "Purchase Error", message: "Unknown error") 
      } 
     } 
    }