IOS solves the Xcode 8 console garbled way _ios

Source: Internet
Author: User
Tags define function uikit

Here are some of the ways that we used to solve the console log output

Xcode8 inside Edit scheme-> Run-> Arguments, environment variables inside add Os_activity_mode = Disable environment variables, this believe everyone will.


Using changes to the Xcode system template

Let's introduce a few C functions

/** *getenv (Get environment variable content) * Define function char * getenv (const char *name);
 * Function Description getenv () is used to get the contents of the parameter name environment variable.
 * Parameter Description *name is the name of the environment variable, and if the variable exists, it returns a pointer to that content.
 * The format of the environment variable is name=value.
 * Return value: Successful execution returns a pointer to the content, and NULL is returned if no match is found for the environment variable name. */-(void) Getenv_test: (char *) env_name {if (getenv (env_name)) {printf ('%s ' s value =%s ', env_name,getenv (env_name
  ));
 }/** *putenv (change or increase environment variable) * Define function int putenv (const char * string);
 * Function Description: putenv () to change or increase the content of the environment variable.
 * The format of the parameter *string is name = value, * If the environment variable was originally present, the contents of the variable are changed according to the parameter string, otherwise the parameter content becomes the new environment variable.
 * Return value: Returns 0 for successful execution, and returns 1 if error occurs.
  */-(void) Putenv_test {char *env_name = "Test_two";
  if (putenv (env_name) = = 0) {printf ("%s =%d", env_name,putenv ("test_two = Two"));
 }/** *unsetenv (remove environment variable) * Define function unsetenv (const char *string);
 * Function Description: unsetenv () to change or increase the content of the environment variable.
 * Parameter *string is the name of the environment variable, * If the environment variable was originally present, then remove the environment variable.
 * Return value: Returns 0 for successful execution, and returns 1 if error occurs.
  */-(void) Unsetenv_test {char *env_name = "Test_one"; if (unsetenv (env_name) = = 0) {printf ("%s is unseted =%s", Env_name,uNsetenv (env_name) = = 0?
  "Yes": "No");
 }/** setenv (change or increase environment variable) * Define function int setenv (const char *name,const char * value,int overwrite);
 * Function Description setenv () is used to change or increase the contents of an environment variable.
 * Parameter name is the environment variable name string.
 * Parameter value is the variable content.
 * parameter overwrite is used to determine if you want to change an existing environment variable.
 If the overwrite is not 0, the original content of the environment variable is changed, and the original content is changed to the variable content referred to in the parameter value.
 If the overwrite is 0 and the environment variable already has content, the parameter value is ignored.
  * Return value execution success returns 0, error occurs when return-1 */(void) setenv_test {char *env_name = "Test_one";
  Char *env_value = "Ooops"; if (setenv (env_name,env_value,1) = = 0) {printf ('%s is seted =%s ', env_name,setenv (env_name,env_value,1) = = 0?
  "Success": "Failed"); }
}

We want to modify the template as follows in the path
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/
Library/Xcode/Templates/Project\ Templates/iOS/Application/Cocoa\ Touch\ Application\ Base.xctemplate

Open the file and search for the following code in the file

<key>main.m:main:UIApplicationMain</key>
            <string> @autoreleasepool {
  return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);
}
</string>

Change it to

<key>main.m:main:UIApplicationMain</key>
            <string> @autoreleasepool {
   * * * This line of code is added code
   *
  /setenv ("Os_activity_mode", "DISABLE", 1);
  Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);
}

The purpose is to add an environment variable to the entry file of the Xcode project created

The effect is as follows


//MAIN.M
//environment_variable
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main (int argc, char * argv[]) 
{
  @autoreleasepool 
{
    setenv ("Os_activity_mode", "Disable", 1);
    Return Uiapplicationmain (argc, argv, Nil, Nsstringfromclass ([Appdelegate class]);
  }

Summarize

The above is the entire content of this article, to solve the Xcode8 to create a new project, the console will appear in the small defects of the wonderful log! I hope to be able to meet this problem friends can help, if there are questions you can message exchange.

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.