title: How do I use SKReceiptRefreshRequest to restore a purchase in StoreKit in iOS?
body: <p>From all the other answers on stack<strong>overflow</strong>, I have not found the answer to this particular question.</p>
  
  <p>I am using SKReceiptRefreshRequest to restore a purchase. I am using a sandbox account. I have the following code:</p>
  
  <pre><code>let request = SKReceiptRefreshRequest()  
  
  request.delegate = self  
  
  request.start()  
  </code></pre>
  
  <p>When the result is a call to requestDidFinish of the SKRequestDelegate protocol. The request I get back has nil for its receiptProperties property. How do I interpret that? The documentation (<a href="https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Restoring.html#//apple_ref/doc/uid/TP40008267-CH8-SW2" rel="nofollow noreferrer">Refreshing the App Receipt</a>) says to check the receipt, but there appears to be nothing to check.</p>
  
  <p>Here is my code when I assume that getting a request back with nil receiptProperties mean that I received back a receipt.</p>
  
  <pre><code>extension SettingsTableViewController: SKRequestDelegate {
  
      func requestDidFinish(_ request: SKRequest) {
  
          print("requestDidFinish")
  
          print("request=", request)
  
          if let receiptRefreshRequest = request as? SKReceiptRefreshRequest {
  
              print("receipt properties=", receiptRefreshRequest.receiptProperties as Any)
  
          }
  
          if iCloudAvailable() {
  
              ubiquitousKeyValueStore.set(true, forKey: UbiquitousKeys.iMessageExtension)
  
              let alertMessage = "iMessage Saved Messages has been restored."
  
              let alert = UIAlertController(title: nil, message: alertMessage, preferredStyle: .alert)
  
              let actionOK = UIAlertAction(title: "OK", style: .cancel, handler: nil)
  
              alert.addAction(actionOK)
  
              present(alert, animated: true, completion: nil)
  
          }
  
      }
  
      func request(_ request: SKRequest, didFailWithError error: Error) {
  
          print("requst(_:didFailWithError:)")
  
          if let receiptRefreshRequest = request as? SKReceiptRefreshRequest {
  
              print("receipt properties=", receiptRefreshRequest.receiptProperties as Any)
  
          } else {
  
              print("request=", request)
          }
  
          print("error=", error)
  
          let alertMessage = "There are no purchases to restore."
  
          let alert = UIAlertController(title: nil, message: alertMessage, preferredStyle: .alert)
  
          let actionOK = UIAlertAction(title: "OK", style: .cancel, handler: nil)
  
          alert.addAction(actionOK)
  
          present(alert, animated: true, completion: nil)
  
      }
  
  }
  </code></pre>