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.