IOS, I think that’s enough for you to buy

Buy more pit, climbed for a long time (at least in the book of the purchase of related articles almost see over), it is understood a point. Useful for you, tell me, there is doubt contact me.
start (recommended to read the first entry)

@import StoreKit; #import "IAPManager.h" @implementation IAPManager + sharedInstance static ID (instancetype) {sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once (& onceToken, sharedInstance = [[IAPManager alloc init] ^{];}); return sharedInstance;} entrance it, came to get a background of the commodity ID (registered on the Apple website the) - (void) payBtnPressed: (NSString * product_id) {// which came in a commercial ID, lzc if ([SKPaymentQueue canMakePayments) / / is allowed to pay the application SKProductsRequest [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet {*request = setWithObject:product_id]]; request.delegate = self; [request start];}else DLog (@" Users are not allowed to purchase ");} / / / / prompt box query after the success of the callback - (void) productsRequest: (SKProductsRequest * request) didReceiveResponse: (SKProductsResponse * response) {/ / (@ DLog disappear here chrysanthemum chrysanthemum" disappeared "); NSArray * products = response.products; if (products.count = self.product = {0!) products[0]; SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:self.product]; //lzc payment.applicationUsername = @ (1000000).StringValue; / / user ID or uid. [[SKPaymentQueue defaultQueue] recharge, addPayment:payment]; / / buy course initiated monitoring, this thing written in the entrance program is good, as to why the next time} if (products.count = = 0) {DLog (@" unable to get the business ");}} / / query failed after callback - (void) request: (SKRequest * request) didFailWithError: (NSError * error) {/ / chrysanthemum disappeared DLog (@" apple ", request the server failed [error% @ localizedDescription]);}

Here is the listening result

Monitor / / result of purchase, each state will end orders, or cheating - (void) paymentQueue: (SKPaymentQueue *) queue updatedTransactions: (NSArray< SKPaymentTransaction *> transactions *) {// when users buy the operation results, it will trigger a callback function below, DLog (@ / / chrysanthemum disappear "to monitor the purchase" (SKPaymentTransaction for); *transaction in transactions (transaction.transactionState)) {switch {case SKPaymentTransactionStatePurchased:// [self completeTransaction:transaction] the success of the transaction; / / / / verify if the user exits, in the middle?? don't know to see the next pit pit pit are pit DLog (@ "end of order"); [[SKPaymentQueue DefaultQueue] finishTransaction:transaction]; / / verify the success, we are trading off, otherwise there will be false information has been verified documents into the program to enter the apple account.. through each case break; case SKPaymentTransactionStateFailed: [self failedTransaction:transaction]; / / break case SKPaymentTransactionStateRestored:// transaction failed method; already purchased the goods DLog (@ "already purchased") [[SKPaymentQueue; defaultQueue] finishTransaction:transaction]; / / consumption type does not support the recovery, so I will not write break; case SKPaymentTransactionStatePurchasing: DLog (@ "already in the list of commodities"); / / Chrysanthemum Break case SKPaymentTransactionStateDeferred: DLog (flower; @ "end state determined"); break; default: break;}}} - (void) failedTransaction: (SKPaymentTransaction * transaction) {if (transaction.error.code! = SKErrorPaymentCancelled) {NSLog (@ "failed purchase");} else {NSLog (@ "user cancel transactions") [[SKPaymentQueue defaultQueue] finishTransaction: transaction];}};

Here is the validation certificate with the server, and the focus is here

- (void) completeTransaction: (SKPaymentTransaction * transaction) {if (! = Nil) {// this stuff I click on goods back in, so it is not a single leakage through judgment, his words left normal flow of DLog (@ "buy validation order"); NSData *data = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] appStoreReceiptURL] path]]; NSString *a = [data base64EncodedStringWithOptions:0]; NSLog (@ base64JSONString, a =---%@--- "); / / get the certificate of NSDictionary * DIC =" uid "@{@: user ID, @" receipt ": A, there are other things back to the user, at least vouchers and ID is a must.}; DLog (@" to verify the information, DIC); / / "% @ save [self addDicToPayAry:dic]; / / put this information to the local, this is the first step you buried in pits, are free to explain [self testForServer:dic]; / / and backstage to two times the necessary verification, else {DLog} (@ leakage process from local take to verify the certificate "); / / self / checkUnTestReceipt]; take the certificate verification from the local to the decomposition of}// not click cell to come in, that is to say the last orders before the end of the day the dog go}

Server, as long as the server response I took the local information removed, because successfully deleted verification is not normal, shows the success of documents are false (with perhaps Apple problems, the tube can not delete), we here with our background server (say the state is verified but did not send back goods the user can call),
, delete. Not only when their own background and interaction, we find in the local village had some words that have no certificate verification, we continue to verify. No words (for the first time also did not exist because once but didn’t delete instructions) are verified. In this process no matter how to end the order.

- (void) testForServer: (NSDictionary *) DIC [[NetWorkManager sharedInstance]postJsonData:dic url:url {WEAKSELF; successBlock:^ (ID responseBody) {DLog (@ "% @ successful payment", responseBody); if ([responseBody[@ "code" isEqualToNumber:@ (200)]]) {DLog (@ 1 verify the successful completion of the transaction OKOKOKOK if (weakSelf.paySuccessBlock); {(weakSelf.paySuccessBlock)); / / UI} [weakSelf tell outside processing removeDicFromPayAry:dic]; / / remove documents and other information from the local DIC if} (verifying receipt-data failure) {DLog (@ "1 verification failed receipt-data"); [weakSelf removeDicFromPayAry:dic];} / / remove if (faulty US server) {[weakSe LF removeDicFromPayAry:dic]; DLog ("1 @ you go to the customer service. We server problems");} / / DLog (@ "the end of my orders,");} failureBlock:^ (NSString *error) {DLog (@ "% @ and their server failed 11", error); / / [weakSelf checkUnTestReceipt]; and their background no contact, so check that there are no saved documents, so continue to verify the details of talk.}]};

The length of the problem, delete deposit voucher vouchers and verification documents.
said again next time and order no end pit (users buy success Apple server suck, users quick temper application, the order is not over) and so on, next time.

8.25, to bury pit, come down
iOS purchase second

It’s still not perfect. First of all