IOS developers use RMStore to simplify in-house purchase code + in-house purchase order verification, iosrmstore

Source: Internet
Author: User

IOS developers use RMStore to simplify in-house purchase code + in-house purchase order verification, iosrmstore

Now many apps have added in-app purchases. There are many tutorials on how to generate and set Apple certificates on the Internet. I will not repeat them here, I recommend a few URLs that I think are more detailed:

Http://www.jianshu.com/p/86ac7d3b593a

Http://blog.csdn.net/shenjie12345678/article/details/40978977

In the project, I used a third party of RMStore to implement the internal purchase code. Because this framework encapsulates the internal purchase code, the code after relying on the framework is very simple:

 

Request Product from appStore:

NSString * productIds = @ [@ "ID_1", @ "ID_2", @ "ID_3"], [[RMStore defaultStore] requestProducts: [NSSet setWithArray: productIds] success: ^ (NSArray * products, NSArray * invalidProductIdentifiers) {if ([products count] = 0) {NSLog (@ "---------------- no product ----------------"); return;} failure: ^ (NSError * error) {NSLog (@ "-------------- failed to request the product ----------------");}];


Purchased items:

NSString * appleProductId = productId; [[RMStore defaultStore] addPayment: appleProductId success: ^ (SKPaymentTransaction * transaction) {NSLog (@ "------ transaction successful ------");} failure: ^ (SKPaymentTransaction * transaction, NSError * error) {NSLog (@ "------ transaction Failed ------"); NSLog (@ "error: % @", error);}];

 

The original tedious code can be done with the above two methods. Detailed information during the purchase process can be obtained from parameters such as transaction and error in the block.

After the purchase is successful, order verification is required to prevent unlimited currency scalpers from being cracked. For more information, see the api receipvalidation Programming Guide.

In order to ensure the accuracy and stability of the verification, it is generally submitted to the backend for verification. On the iOS end, we need to obtain the order data and then send the data to the backend:

NSURL * receiptURL = [[NSBundle mainBundle] Response]; NSData * receiptData = [NSData dataWithContentsOfURL: receiptURL]; NSString * receiptStr = [receiptData response: Response]; // send receiptStr to the server;

Originally in the SKPaymentTransaction class, there was the receipparameter, directly transaction. you can obtain the verification data, but the verification data has expired after iOS7. Therefore, you can select the method to obtain the receipt based on the system version that the app adapts.

After receiving this string, the background partner sends it to the Apple Server through the following url. Note that the verification address used for testing and publishing is different.

Sandbox test: https://sandbox.itunes.apple.com/verifyReceipt

After the app is published:https://buy.itunes.apple.com/verifyReceipt

After verification, the Apple Server Returns the verification information about 3 seconds. The server's partner confirms whether the order is valid Based on the returned information. The parameters returned by the specific app can be found in the api.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.