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:



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:

After the app is published:

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

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.