- To add an IAP to an app, you must register your own product identifiers ). What is a product identifier?
Product identifiers is a string used to identify each item you sell in the app. App Store uses product identifiers to retrieve product information. identifiers can only contain uppercase/lowercase letters (A-Z), numbers (0-9), underscores (-), and DOTS (.). You can arrange these elements at will, but we recommend that you use reverse domain names when creating identifiers, such as com. companyName. application. productid.
Note: product identifiers have no relationship with Apple IDs and bundle IDs. They may look like bundle IDs, but they are different. Therefore, you cannot use the Apple ID or bundle ID in the code to replace the product identifier.
- How to create a product identifier?
The IAP form (Thein-app purchases form) is used to generate the IAP product. It contains the product ID field, which must be filled in the table. This field can be used to specify the product identifier for your product. You can follow these steps to create a product identifier:
1. log on to iTunes connect and click the Manage Your applications module on the home page.
2. Go to the manage your apps page and you will see a list of all your applications. Select the app for the product you want to create IAP, click the manage in-app purchases button on the next page, and then click Create.
3. Select the IAP product type. ITunes connect will take you to the IAP form, which contains the "save" button. Complete the product ID and other fields in the form.
Note: Once a product identifier is created, it cannot be modified. In addition, if the application review fails, the product identifier cannot be used again.
- How do I use a product identifier in an app?
First, create skproductsrequest and upload the product identifier list to initwithproductidentifiers to read the product information.
- When testing in-APP purchase in the sandbox environment, why do I get the error message "payment requests are restricted to products returned as valid via store Kit's didreceiveresponse method?
The user interface of the app executing in-APP purchase must have the products that the App Store allows for purchase. Before you decide to display the products used for purchase on the user interface, your app must first send a product request to the app store.
- Storekit provides two solutions for payment requests:
[Skpayment identifier: product_id] [skpayment paymentwithproduct: your_skproduct_object] Apple recommends that you use [skpayment paymentwithproduct: your_skproduct_object] to ensure that you are in a valid product payment request State, at the same time, make sure that you can purchase your product. Therefore, only the product information returned by the App Store must be displayed. For more information about product display in the app, see In-app
Feature Delivery Section of the purchase programming guide.
- What are the types of In-APP purchase?
In-APP purchase has three types: consumable: one-time purchase, the simplest type, no need to save historical records. Nonconsumable: you can buy a product only once, and then you can view the product on all your devices. Subscriptions: The subscription mode allows you to purchase the last product multiple times. After purchasing the product, you can view the product on all your devices.
- In iOS, do I need to purchase the content purchased in the program again after the system is reinstalled using the IAP method? For example, the filter in Camera +.
No. Taking Camera + as an example, the lower option restore purchases in the menu can help you unlock the purchased filter. This option is basically provided for any app that implements the IAP function, or the app prompts that it has been purchased for the Second Purchase.
Consumption (such as game gold coins) needs to be purchased. You do not need to purchase function classes. Some applications provide "Restore purchases". If you do not have them, you can try again and a message indicating that you have paid for them will be displayed.
- Can IAP be free for a limited time? I want to make a free download and some content free of charge, but read more content requires paid to unlock the read application. In this way, can I set the IAP price to 0 for free?
You can set it to $0.99.
- When you create a product ID, you have selected an error when selecting the price. The program has not been submitted. Can you change it?
Yes, in the application information.
- An error occurred while recovering the backup during ios5 GM upgrade, resulting in the loss of In-APP purchase. Is there a way to restore it? Some in-APP purchase operations were performed on the iPad, but an error occurred while recovering the backup during ios5 GM upgrade, resulting in the recovery of all applications before the upgrade, all other personal information is lost. Purchase records can be found on iTunes. Specifically, I bought the splashtop software that uses the iPad as the second monitor, xdisplay.
In-APP purchase is divided into several types. The most common is non-consumable, which only requires one purchase. If this type is used, the same item can be recovered after another purchase without additional charges. If the app is doing well, a restore function should be provided to specifically restore non-consumable products that have been purchased previously.
- How many IAP product IDS can be created for each app in iTunes connect?
See the IAP Registration Section in the iTunes connect developer guide.
- I cannot find the manage in-APP purchase (manage IAP) button in iTunes connect. What should I do?
The following are possible reasons why the manage in-APP purchase button cannot be used:
A. It is not the Administrator (Admin) or developer (technical) account of iTunes connnect.
B. do not agree to the latest IOS or Mac developer license agreement.
C. The latest paid Application Protocol (paid applications contract) has not taken effect.
- Do I have to upload the binary code of the program to test the IAP?
This is not necessary.
Important: Do not upload the development binary to iTunes connect unless your application is ready for Apple's review. If the binary code in iTunes connect is incomplete, the binary code may be rejected. Once the binary code is approved, you can test the in-APP purchase function.
- What should I do if the error "your account information has changed" is displayed?
The error "your account information has changed" occurs because you are using the device's test account when testing the IAP. The solution is to exit the account, create a new test account in iTunes connect, and use the new test account to test IAP.
- Why is my product identifier returned in invalidproductidentifiers?
It may be due to the following reasons:
A. The financial demand form has not been filled out (please refer to the "contract, tax and Bank Information" section in this document)
B. The correct app ID is not used.
C. The correct provisioning profile closely related to the app ID is not used.
D. The correct product identifier is not used in the code. For more information about product identifiers, see technical question and answer, Article 1-IAP product identifiers.
E. You have not cleared the IAP products promoted in iTunes connect.
F. Maybe you have modified your product, but it does not take effect on the App Store server.
G. Apple rejected your latest Binary Code submitted to iTunes connect.
- What should I do if the error "you have bought this product but the product has not been downloaded" appears?
Your application did not call skpaymentqueue's finishtransaction. Call finishtransaction: allows you to remove transactions from the payment queue.
- What should I do if the error "you have successfully purchased and click" OK "to download the instance for free again?
This message is a reminder, not an error. This indicates that you are trying to purchase a non-consumable product that you have already purchased. No fee will be deducted when purchasing a non-consumable product.
- Call payment queue's restorecompletedtransactions: The method cannot restore any product of the app.
This may be due to the following reasons:
You have not purchased any non-consumable products.
Subscription products or non-consumable products you are trying to restore are unrecoverable types.
Restorecompletedtransactions: The method can only restore non-consumable products.
Note: store kit does not call the paymentqueue: updatedtransactions: method when there is no recoverable product.
- When should I restore the in-APP purchase product?
In either of the following situations, you can restore automatically updated subscription products and non-consumable products:
A. install it on other devices of the customer.
B. reinstall the device on which the associated application is deleted.
- How can I solve the problem of "This is not a user account used for testing, Please create a new account in the sandbox environment?
This error occurs because you are using the iTunes user account when confirming the purchase information. The solution is to exit the account and use your IAP to test the account.
- An error occurred while verifying the receipt with a string (IOS ).
There may be the following reasons:
A. In your iOS app, you didn't use 64-bit encoding to encode the retrieval data,
B. There is no valid return ticket. your return ticket probably uses an equal sign to separate the key and value, and uses a semicolon to separate the keywords.
C. Valid return orders use colons to separate keys and values and use commas to separate keywords,
The following table lists valid ticket return samples.
Receept: {"signature ":"... "," purchase-Info ":"... "," pod ":"... "," signing-status ":"... "}
- I updated the iOS app that uses in-APP purchase. How can I test it (IOS )?
Whether or not the updated app is correctly executed in-APP purchase, perform the following steps if you want to test it:
Install the original app in ad hoc distribution mode.
Install the updated app in ad hoc distribution mode to verify that the app completely overwrites the original app.
Try to execute in-APP purchase from the updated app.
- Which URL should I use to verify the receipt (IOS )?
Use the sandbox URL when testing the app in the sandbox environment, you can also use this URL when the app is in the audit status: https://sandbox.itunes.apple.com/verifyReceipt use the product URL once your app is on the App Store, you will use the product URL: http://buy.itunes.apple.com/verifyReceipt
- How do I verify receipt (IOS )?
For the first time, the product URL is generally used to verify the receipt. If you receive a 21007 status code, use the sandbox URL. This method can be used when the app is being tested, tested in a sandbox environment, or mounted to the App Store to avoid switching between URLs,
Note: The "21007" status code table indicates that receipis a sandbox receip.
Http://www.cocoachina.com/special/iap.html
Procedure
1. Add storekit. framework, write your own storeobsever for transaction processing. The Code is as follows. The completetransaction and failedtransaction functions are customized to handle transaction Success and Failure. Other functions are required by the skpaymenttransactionobserver proxy.
Code
# Import <Foundation/Foundation. h>
# Import <storekit/storekit. h>
# Import <storekit/skpaymenttransaction. h>
@ Interface mystoreobserver: nsobject <skpaymenttransactionobserver> {
}
-(Void) paymentqueue :( skpaymentqueue *) queue updatedtransactions :( nsarray *) transactions;
-(Void) purchasedtransaction: (skpaymenttransaction *) transaction;
-(Void) completetransaction: (skpaymenttransaction *) transaction;
-(Void) failedtransaction: (skpaymenttransaction *) transaction;
-(Void) paymentqueuerestorecompletedtransactionsfinished: (skpaymenttransaction *) transaction;
-(Void) paymentqueue :( skpaymentqueue *) paymentqueue restorecompletedtransactionsfailedwitherror :( nserror *) error;
@ End
-(Void) paymentqueue :( skpaymentqueue *) queue updatedtransactions :( nsarray *) the transactions function is used to update the transactions status.
-(Void) paymentqueue :( skpaymentqueue *) queue updatedtransactions :( nsarray *) Transactions {
For (skpaymenttransaction * transaction in transactions ){
Switch (transaction. transactionstate ){
Case skpaymenttransactionstatepurchased:
[Self completetransaction: transaction];
Break;
Case skpaymenttransactionstatefailed:
[Self failedtransaction: transaction];
Break;
Case skpaymenttransactionstaterestored:
Break;
Default:
Break;
}
}
}
2. Add storeobsever to the program. It is best to add it in applicationdidfinishlaunching.
Mystoreobserver * tempobserver = [[mystoreobserver alloc] init];
Self. Observer = tempobserver;
[Tempobserver release];
[[Skpaymentqueue defaultqueue] addtransactionobserver: Self. Observer];
3. Send a payment request and implement skproductsrequestdelegate in the corresponding class. Do not forget to define the identifier of your product.
// Request Product Information
# Define kmyfeatureidentifierYourproductidentifiers
(Your own product identifiers)
Skproductsrequest * request = [[skproductsrequest alloc] initwithproductidentifiers:
[Nsset setwithobject: kmyfeatureidentifier];
Request. Delegate = self;
[Request start];
The Code related to the proxy method. If the request is successful, you can send a payment request.
# Pragma mark request delegate
//! Receive product message
-(Void) productsrequest :( skproductsrequest *) Request didreceiveresponse :( skproductsresponse *) response {
Skpayment * payment = [skpayment paymentwithproductidentifier: kmyfeatureidentifier];
[[Skpaymentqueue defaultqueue] addpayment: payment];
[Request autorelease];
}
-(Void) Request :( skrequest *) Request didfailwitherror :( nserror *) error {
Uialertview * alerview = [[uialertview alloc] initwithtitle: @ "alert" message: [error localizeddescription] delegate: Nil C
Ancelbuttontitle: nslocalizedstring (@ "close", nil) otherbuttontitles: Nil]; [alerview show]; [alerview release];
}
4. The next step is Apple's payment-related processing. You need to click the button to confirm the payment.
5. After the transaction is completed, you need to verify to Apple whether the transaction is successful. Otherwise, if the product is not successful, you will lose the product, in 1, we can see that when the transaction is successful, the custom completetransaction function will be called. In this function, we need to verify that transactionreceipt is about verifying skpaymenttransaction transactionreceiponly when skpaymenttransaction is completed, that is, transactionstate is set to skpaymenttransactionstatepurchased or
Skpaymenttransactionstaterestored is created. Therefore, you can only verify transactionreceept in these two statuses.
The original ideas and steps are as follows:
A converts transactionreceept to nsstring from the skpaymenttranscation instance
Nsstring * temptransactionreceept = [[nsstring alloc] initwithdata: [mytransaction transactionreceept] encoding: nsutf8stringencoding];
If you use the nslog method to write it as follows, there are many '+' {"signature" =
"Aznzdoggtjbu/wmqz4ssd3lgkxbwr +/strong + strong/9yye00009x + U3/strong + strong/izsmu + weight/3cgidg91b/strong/ response + response/response = ";
"Purchase-Info" = "success ";
"Pod" = "100"; "signing-status" = "0 ";}
B then submits the request to the server through the POST method. Here, the request is only sent to the server for verification. The Code is as follows,
Nsstring * requeststirng = [nsstring stringwithformat: @ "receipt_data = % @", temptransactioreceept];
Requeststirng = [requeststirng stringbyaddingpercentescapesusingencoding: nsutf8stringencoding];
Nsdata * postdata = [nsdata datawithbytes: [requeststirng utf8string] length: [requeststirng length];
Nsmutableurlrequest * connectionrequest = [nsmutableurlrequest requestwithurl: [nsurl urlwithstring: [kurl stringbyaddingpercentescapesusingencoding: nsutf8stringencoding];
[Connectionrequest sethttpmethod: @ "Post"];
[Connectionrequest settimeoutinterval: 120.0];
[Connectionrequest setcachepolicy: nsurlrequestuseprotocolcachepolicy];
[Connectionrequest sethttpbody: postdata];
If an error occurs, the server uses the receipt_data passed in to verify the request to Apple. However, however, the temptransactionreceept written in the background using the nslog method can verify to apple that the URL-based string sent to the server cannot complete the urlencode by comparing the error causes, in this example, the + cannot be automatically converted to encoding, because in objective-C, the nsstring cannot be truly implemented as the URL encode,
For the solution, refer to the following address:
Http://simonwoodside.com/weblog/2009/4/22/how_to_really_url_encode/
However, this problem still cannot be solved after I use the method given above for encoding. The reason is unknown.
Solution:
Convert + to % 2B, and change the code in step a
Nsstring * temptransactionreceept = [[nsstring alloc] initwithdata: [mytransaction transactionreceept] encoding: nsutf8stringencoding];
Temptransactionreceept = [temptransactionreceept stringbyreplacingoccurrencesofstring: @ "+" withstring: @ "% 2B"];
6. XML is a custom class in the server-side verification code. The job of getheader is to post the receipt data to Apple and return the returned result.
$ Url = "https://buy.itunes.apple.com/verifyReceipt";/$ receept = json_encode (Array ("receipt_data" => base64_encode ($ receipt_data )));
$ Response_json = $ XML-> getheader ($ URL, $ receipt );
$ Response = json_decode ($ response_json ['content'], true );
The code for getheader is as follows: public function getheader ($ URL, $ data ){
$ CH = curl_init ();
$ Timeout = 300; // set to zero for no timeout
Curl_setopt ($ ch, curlopt_url, $ URL );
// Curl_setopt ($ ch, curlopt_encoding, 'gzip ');
Curl_setopt ($ ch, curlopt_ssl_verifyhost, 1); // post to https
Curl_setopt ($ ch, curlopt_ssl_verifypeer, false );
Curl_setopt ($ ch, curlopt_post, true );
Curl_setopt ($ ch, curlopt_postfields, $ data );
Curl_setopt ($ ch, curlopt_returntransfer, 1 );
Curl_setopt ($ ch, curlopt_followlocation, 1); // follow the page Jump
// Curl_setopt ($ ch, curlopt_header, true );
Curl_setopt ($ ch, curlopt_connecttimeout, $ timeout );
$ Handles = curl_exec ($ ch );
$ Header = curl_getinfo ($ ch );
Curl_close ($ ch );
$ Header ['content'] = $ handles;
Return $ header;
}
Http://www.cocoachina.com/bbs/read.php? Tid-11357.html