Storage of IOS print logs (i)

Source: Internet
Author: User

When we are actually debugging the app, as a developer we can easily view the relevant print information via the debug area of Xcode. When the tester is testing the app, once the crash is present, we need to save the relevant print information,

So that you can see the reason behind the trace crash. Here we can write the print information to the sandbox system. Not much to say, directly on the code.

1- (void) Redirectnslogtodocumentfolder2 {3     if(Isatty (Stdout_fileno))4     {5NSLog (@"Real-Machine debugging eliminates the need to write print information to a file. \ n");6         return;7     }8Nsarray *paths =nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);9NSString *documentdirectory = [Paths Objectatindex:0];TenNSString *filename = [NSString stringWithFormat:@"PrintfInfo.log"]; OneNSString *logfilepath =[Documentdirectory stringbyappendingpathcomponent:filename]; A     //Delete the existing file first -Nsfilemanager *defaultmanager =[Nsfilemanager Defaultmanager]; - [Defaultmanager Removeitematpath:logfilepath error:nil]; the      -     //enter log into file -Freopen ([LogFilePath cstringusingencoding:nsasciistringencoding],"A +", stdout); -Freopen ([LogFilePath cstringusingencoding:nsasciistringencoding],"A +", stderr); +}

At the same time we call this method in the app launch Didfinishlaunchingwithoptions function.

1 //---------------------writes the print information to the sandbox file--------------------//2Uidevice *device =[Uidevice Currentdevice];3     if(! [Device model] Isequaltostring:@"IPhone Simulator"])4     {5         //start saving log files6 [self redirectnslogtodocumentfolder];7     }8  //--------------------------------------------------------------//

Testers can go to Apple's official website to download itunes from Windows, connect to the computer, open itunes and click on the iphone in the upper right corner. Find your app in the app and find the "PrintfInfo.log" folder in its corresponding document.
Drag-and-drop directly onto the desktop and open with text editing to see the appropriate print information.

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.