2016-12-31 11 views
0

Ich habe in App-Kauf in meinem app.I impelmented haben this tutorialProblem mit In-App-Kauf in iOS?

Jetzt in meiner app gefolgt, wenn ich Last Produkte versuchen, dann ist es nicht load.It Fehler zeigt, wie nicht zu iTunes store.I verbinden können, sind craeted Ein Produkt bei iTunes.

Unten ist der Code

/ 

    * 
    * Copyright (c) 2016 Razeware LLC 
    * 
    * Permission is hereby granted, free of charge, to any person obtaining a copy 
    * of this software and associated documentation files (the "Software"), to deal 
    * in the Software without restriction, including without limitation the rights 
    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
    * copies of the Software, and to permit persons to whom the Software is 
    * furnished to do so, subject to the following conditions: 
    * 
    * The above copyright notice and this permission notice shall be included in 
    * all copies or substantial portions of the Software. 
    * 
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
    * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
    * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
    * THE SOFTWARE. 
    */ 

    import StoreKit 

    public typealias ProductIdentifier = String 
    public typealias ProductsRequestCompletionHandler = (_ success: Bool, _ products: [SKProduct]?) ->() 

    open class IAPHelper : NSObject { 

     static let IAPHelperPurchaseNotification = "IAPHelperPurchaseNotification" 
     fileprivate let productIdentifiers: Set<ProductIdentifier> 
     fileprivate var purchasedProductIdentifiers = Set<ProductIdentifier>() 
     fileprivate var productsRequest: SKProductsRequest? 
     fileprivate var productsRequestCompletionHandler: ProductsRequestCompletionHandler? 

     public init(productIds: Set<ProductIdentifier>) { 
     productIdentifiers = productIds 
     for productIdentifier in productIds { 
      let purchased = UserDefaults.standard.bool(forKey: productIdentifier) 
      if purchased { 
      purchasedProductIdentifiers.insert(productIdentifier) 
      print("Previously purchased: \(productIdentifier)") 
      } else { 
      print("Not purchased: \(productIdentifier)") 
      } 
     } 
     super.init() 
     SKPaymentQueue.default().add(self) 
     } 

    } 

    // MARK: - StoreKit API 

    extension IAPHelper { 

     public func requestProducts(completionHandler: @escaping ProductsRequestCompletionHandler) { 
     productsRequest?.cancel() 
     productsRequestCompletionHandler = completionHandler 

     productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers) 
     productsRequest!.delegate = self 
     productsRequest!.start() 
     } 

     public func buyProduct(_ product: SKProduct) { 
     print("Buying \(product.productIdentifier)...") 
     let payment = SKPayment(product: product) 
     SKPaymentQueue.default().add(payment) 
     } 

     public func isProductPurchased(_ productIdentifier: ProductIdentifier) -> Bool { 
     return purchasedProductIdentifiers.contains(productIdentifier) 
     } 

     public class func canMakePayments() -> Bool { 
     return SKPaymentQueue.canMakePayments() 
     } 

     public func restorePurchases() { 
     SKPaymentQueue.default().restoreCompletedTransactions() 
     } 
    } 

    // MARK: - SKProductsRequestDelegate 

    extension IAPHelper: SKProductsRequestDelegate { 

     public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) { 
     let products = response.products 
     print("Loaded list of products...") 
     productsRequestCompletionHandler?(true, products) 
     clearRequestAndHandler() 

     for p in products { 
      print("Found product: \(p.productIdentifier) \(p.localizedTitle) \(p.price.floatValue)") 
     } 
     } 

     public func request(_ request: SKRequest, didFailWithError error: Error) { 
     print("Failed to load list of products.") 
     print("Error: \(error.localizedDescription)") 
     productsRequestCompletionHandler?(false, nil) 
     clearRequestAndHandler() 
     } 

     private func clearRequestAndHandler() { 
     productsRequest = nil 
     productsRequestCompletionHandler = nil 
     } 
    } 

    // MARK: - SKPaymentTransactionObserver 

    extension IAPHelper: SKPaymentTransactionObserver { 

     public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { 
     for transaction in transactions { 
      switch (transaction.transactionState) { 
      case .purchased: 
      complete(transaction: transaction) 
      break 
      case .failed: 
      fail(transaction: transaction) 
      break 
      case .restored: 
      restore(transaction: transaction) 
      break 
      case .deferred: 
      break 
      case .purchasing: 
      break 
      } 
     } 
     } 

     private func complete(transaction: SKPaymentTransaction) { 
     print("complete...") 
     deliverPurchaseNotificationFor(identifier: transaction.payment.productIdentifier) 
     SKPaymentQueue.default().finishTransaction(transaction) 
     } 

     private func restore(transaction: SKPaymentTransaction) { 
     guard let productIdentifier = transaction.original?.payment.productIdentifier else { return } 

     print("restore... \(productIdentifier)") 
     deliverPurchaseNotificationFor(identifier: productIdentifier) 
     SKPaymentQueue.default().finishTransaction(transaction) 
     } 

     private func fail(transaction: SKPaymentTransaction) { 
     print("fail...") 
     if let transactionError = transaction.error as? NSError { 
      if transactionError.code != SKError.paymentCancelled.rawValue { 
      print("Transaction Error: \(transaction.error?.localizedDescription)") 
      } 
     } 

     SKPaymentQueue.default().finishTransaction(transaction) 
     } 

     private func deliverPurchaseNotificationFor(identifier: String?) { 
     guard let identifier = identifier else { return } 

     purchasedProductIdentifiers.insert(identifier) 
     UserDefaults.standard.set(true, forKey: identifier) 
     UserDefaults.standard.synchronize() 
     NotificationCenter.default.post(name: NSNotification.Name(rawValue: IAPHelper.IAPHelperPurchaseNotification), object: identifier) 
     } 
    } 

Bitte leiten, was ist das Problem?

EDIT: Hat fehlgeschlagen mit Fehler wird aufgerufen. "Fehler beim Laden der Liste der Produkte."

+0

Was ist der Fehler? –

+0

Keine Produkte erhalten – iOSGuy

Antwort

0

Vergewissern Sie sich, dass Sie alle iTunes-Produktionskonten auf dem Gerät abgemeldet haben.

Ich bekam diesen Fehler auf meinem Testtelefon, das mit meinem tatsächlichen iTunes-Konto angemeldet war. Sie können Apps nicht mit Ihrem Produktions-iTunes-Konto testen, daher der Fehler. Ich wünschte nur, Apple einen besseren Fehler zur Verfügung gestellt, um diese Vermutung zu vermeiden ...

Die Lösung zu ein Testbenutzerkonto erstellen ist, wenn Sie noch kein Konto haben. Testen Sie den In-App-Kauf mit diesem Konto.

Hinweis: Falls Sie keine Produkte erhalten, stellen Sie bitte sicher, dass Sie die Produktkennung verwenden, während Sie eine Anfrage senden, die genau der Produktkennung auf itunes entspricht.

Ein weiterer dummer Grund, wir begegnen diesem Fehler, wenn wir auf Simulator laufen. Prüfen Sie, ob

Ihre Anwendung wird im Simulator ausgeführt wird, die nicht In-App Kauf

+0

Muss ich mich mit dem Testerkonto für das Produkt anmelden – iOSGuy

+0

Muss ich mich mit dem Testerkonto anmelden, um Produkte zu erhalten - – iOSGuy

+0

Ja. Sonst kann der In-App-Kauf nicht getestet werden. –

0

Nach der Anmeldung aus dem iTunes & iCloud-Account unterstützt zurückgesetzt i mein iOS-Gerät & In App-Kauf gearbeitet .Obwohl ich nicht weiß warum.

Sie müssen nicht auf dem iOS-Gerät angemeldet sein, um Produkte aus dem App-Kauf zu erhalten.Für den Kauf der Produkte müssen wir im Gerät angemeldet sein.