How to run code during debugging during iOS development

Source: Internet
Author: User

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]; 

 

 

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.