title: Swift in app purchase not working
body: <p>I am making an iPhone game. I am following the Swift In-App Billing tutorial for gaming money settlement. I finished all the Swift coding and build, and I hit the button on the screen but the popup does not pop up. Please let me know what's wrong with my code. </p>
  
  <pre><code> import UIKit
   import AVFoundation
   import StoreKit
  
   class ViewController: UIViewController,UIScrollViewDelegate,SKProductsRequestDelegate, SKPaymentTransactionObserver {
  
  
  
  @IBOutlet var outAddCoins: UIButton! 
  
  
  @IBAction func btnAddCoins(_ sender: Any) {
      for product in list {
          let prodID = product.productIdentifier
          if(prodID == "Add500000Credit") {
              p = product
              buyProduct()
          }
      }
  }
  
  
  func buyProduct() {
      print("buy " + p.productIdentifier)
      let pay = SKPayment(product: p)
      SKPaymentQueue.default().add(self)
      SKPaymentQueue.default().add(pay as SKPayment)
  }
  
  
  func addCoins() {
      playerMoney += 500000
      MoneyLabel.text = "\(playerMoney)"
  }
  
  var list = [SKProduct]()
  var p = SKProduct()
  
  
  
  
  
  
  func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
      print("product request")
      let myProduct = response.products
      for product in myProduct {
          print("product added")
          print(product.productIdentifier)
          print(product.localizedTitle)
          print(product.localizedDescription)
          print(product.price)
  
          list.append(product)
      }
  
      outAddCoins.isEnabled = true 
  }
  
  
  
  
  func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
      print("transactions restored")
      for transaction in queue.transactions {
          let t: SKPaymentTransaction = transaction
          let prodID = t.payment.productIdentifier as String
  
          switch prodID {
  
              case "Add500000Credit":
                  print("add coins to account")
                  addCoins()
              default:
                  print("IAP not found")
          }
      }
  }
  
  
  
  
  
  
  func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
      print("add payment")
  
      for transaction: AnyObject in transactions {
          let trans = transaction as! SKPaymentTransaction
          print(trans.error)
  
          switch trans.transactionState {
          case .purchased:
              print("buy ok, unlock IAP HERE")
              print(p.productIdentifier)
  
              let prodID = p.productIdentifier
              switch prodID {
  
                  case "Add500000Credit":
                      print("add coins to account")
                      addCoins()
                  default:
                      print("IAP not found")
              }
              queue.finishTransaction(trans)
          case .failed:
              print("buy error")
              queue.finishTransaction(trans)
              break
          default:
              print("Default")
              break
          }
      }
  }
  </code></pre>
  
  <p>and this is viewdidload part</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
  
  
      outAddCoins.isEnabled = false
  
  
  
  
  
  
  
      if(SKPaymentQueue.canMakePayments()) {
          print("IAP is enabled, loading")
          let productID: NSSet = NSSet(objects: "Add500000Credit")
          let request: SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set&lt;String&gt;)
          request.delegate = self
          request.start()
      } else {
          print("please enable IAPS")
      }
      }
  </code></pre>
  
  <p>I am using the latest version of Xcode. I have completed all the configuration for in-app purchases in iTunes Connect, but the purchase pop-up does not pop up after the build. I would appreciate your help.</p>
  
  <pre><code>buy Add500000Credit
  add payment
  nil
  Default
  add payment
  Optional(Error Domain=SKErrorDomain Code=0 "can not connect to the iTunes Store" UserInfo={NSLocalizedDescription=can not connect to the iTunes Store})
  buy error
  </code></pre>