During the development process, we often use nslog for tracking debugging, but these debugging may not be desired in the released product.CodeRun. Here is a tip.
You can use the following method when writing code:
# Ifdef debug//Debug mode code...# Else//Code of the release mode...# Endif
Debug is defined in xcode's default project. You can also add other constant definitions based on your actual situation.
In xcode, select the root node at the top left of the navigation area, select project/build settings, and enter debug in the search box to view the definition, as shown in:
To test the code running effect in different modes, you can select product/scheme/edit scheme and modify build configuration, as shown in:
Tip: the release mode cannot be run on a real machine. You can select the simulator to run and view the effect.
You can use this technique when developing an IAP application so that you do not need to modify the verification address every time. The sample code is as follows:
Definition code:
# DefineItms_prod_verify_receipt_url @ "https://Buy.itunes.apple.com/verifyreceept"# DefineItms_sandbox_verify_receipt_url @ "https://Sandbox.itunes.apple.com/verifyreceept ";
Use some code:
Nsstring * encodingstr = [Transaction. transactionreceept base64encodedstring]; Nsstring * URL; # ifdef debug URL = Itms_sandbox_verify_receipt_url; # Else URL =Itms_prod_verify_receipt_url; # Endif // Create a POST request. Nsstring * payload = [Nsstring stringwithformat: @" {\ " Receip-data \ " : \ "% @ \", \ "Password \": \ "% @\"} " , Encodingstr, itc_content_provider_shared_secret]; nsdata * Payloaddata =[Payload datausingencoding: nsutf8stringencoding]; nsmutableurlrequest * Request = [Nsmutableurlrequest requestwithurl: [nsurl urlwithstring: url]; [Request sethttpmethod: @" Post " ]; [Request sethttpbody: payloaddata]; nsurlconnection * Conn = [[nsurlconnection alloc] initwithrequest: Request Delegate : Self]; [conn start];