objective c - iOS 7: in app purchase receipt validation and verification -


i new receipt validation in ios. have implemented in-app purchase successfully. wish include receipt validation part in in-app puchase.

my in-app purchase 3 products. want before purchase of each single product in app, receipt validation should performed.

for followed following link: official apple developer tutorial

i managed receipt data, puzzled after getting receipt data. how send apple server verification , start in-app purchase process?

following code:

-(void)paymentqueue:(skpaymentqueue *)queue updatedtransactions:(nsarray *)transactions {  nslog(@"transactions count : %d",transactions.count);  bool flgisproductrestorable=no;  (skpaymenttransaction *transaction in transactions) {     switch (transaction.transactionstate) {         case skpaymenttransactionstatepurchasing:         {             // show wait view here             //statuslabel.text = @"processing...";              nslog(@"processing...");         }             break;          case skpaymenttransactionstatepurchased:         {             [[skpaymentqueue defaultqueue] finishtransaction:transaction];             [svprogresshud dismiss];             // remove wait view , unlock feature 2             //statuslabel.text = @"done!";             nslog(@"success : %@ = %@",transaction.payment.productidentifier,transaction.transactionidentifier);             nsurl *receipturl = [[nsbundle mainbundle] appstorereceipturl];             nsdata *receipt = [nsdata datawithcontentsofurl:receipturl];             nslog(@"%@",receipt);              nserror *error;             nsdictionary *requestcontents = @{                                               @"receipt-data": [receipt base64encodedstringwithoptions:0]                                               };             nsdata *requestdata = [nsjsonserialization datawithjsonobject:requestcontents                                                                   options:0                                                                     error:&error];              if (!requestdata) { /* ... handle error ... */ }              // create post request receipt data.             nsurl *storeurl = [nsurl urlwithstring:@"https://sand.itunes.apple.com/verifyreceipt"];             nsmutableurlrequest *storerequest = [nsmutableurlrequest requestwithurl:storeurl];             [storerequest sethttpmethod:@"post"];             [storerequest sethttpbody:requestdata];              // make connection itunes store on background queue.             nsoperationqueue *queue = [[nsoperationqueue alloc] init];             [nsurlconnection sendasynchronousrequest:storerequest queue:queue                                    completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) {                                        if (connectionerror) {                                            /* ... handle error ... */                                        } else {                                            nserror *error;                                            nsdictionary *jsonresponse = [nsjsonserialization jsonobjectwithdata:data options:0 error:&error];                                            nslog(@"response : %@",jsonresponse);                                            if (!jsonresponse) { /* ... handle error ...*/ }                                            /* ... send response device ... */                                        }                                    }];               [self ws_ebookdetail:transaction.transactionidentifier];          }... 

i have copy pasted receipt retrieval code apple link have given in question.

what do next?

keep in mind apple recommends securely send receipt data server , call servers. calls apple's servers not secure.

you can local receipt validation in app. see validating receipts locally information on how this.

there great wwdc video 2014 "preventing unauthorized purchases receipts" goes detail implementing on device receipt validation.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -