title: Standard checking if user has active subscription(auto renewable subscription). IOS Swift
body: <p>I did a lot of reading about auto renewable subscription but I have problem on how to check if a user has active subscription.</p>
  
  <p>this is how I get the receipt</p>
  
  <pre><code>func validateRecipt(callback:(receipt:NSDictionary?)-&gt;()){
          let recuptUrl = NSBundle.mainBundle().appStoreReceiptURL
          if let receipt: NSData = NSData(contentsOfURL:recuptUrl!) {
  
              //https://sandbox.itunes.apple.com/verifyReceipt    //TEST ENVIRONMENT
              //https://buy.itunes.apple.com/verifyReceipt        //PRODUCTION ENVIRONMENT
              let request = NSMutableURLRequest(URL: NSURL(string: "https://sandbox.itunes.apple.com/verifyReceipt")!, cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy, timeoutInterval: 10)
  
              let session = NSURLSession.sharedSession()
              request.HTTPMethod = "POST"
              let receiptdata:NSString = receipt.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
              let payload:NSDictionary = {["receipt-data" : receiptdata, "password" : "mySharedKey"]}()
             //, password\" : \"" + EGConstants.sharedSecret + "\" }"
  
              do {
  
              let payloadData:NSData = try(NSJSONSerialization.dataWithJSONObject(payload, options: NSJSONWritingOptions(rawValue: 0)))
  
              request.HTTPBody = payloadData
              let task = session.dataTaskWithRequest(request) { (data, response, err) in
  
                  do {
                      let json = try(NSJSONSerialization.JSONObjectWithData(data!, options: .MutableLeaves) as? NSDictionary)
  
                      if(err != nil) {
                          print(err!.localizedDescription)
                          let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
                          print("Error could not parse JSON: '\(jsonStr)'")
                          callback(receipt: nil)
                      }
                      else {
                          if let parseJSON = json {
  
  
                              callback(receipt: parseJSON)
                          }
                          else {
                              let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding)
                              print("Recipt Error: \(jsonStr)")
                              callback(receipt: nil)
                          }
                      }
                  } catch {
  
                  }
              }
  
  
  
              task.resume()
  
              } catch {}
          }
      }
  </code></pre>
  
  <p>my questions are: <br><br>
  1. How to check if user has active subscription using Receipt? (do i need to parse the receipt and get the last <code>expires_date</code> of last transaction of <code>product subscription</code>?)
  <br><br>
  2. Is it fine to refresh receipt every time I launch the app?(so that I could check if user cancelled his subscription) if not when do I need to do the refresh receipt?</p>
  
  <p>ps. If I have wrong concept or questions please guide me to right path. Thanks in advance</p>