for those engineers who do back-end development, lookLOGSolutionBugshould be a matter of course, but I am exposed to the mobile application development engineer inside, many people do not have this consciousness, checkBugis always repeated over and over again trying to debug, especially for some less easily reproducedBugoften burn. andIOSthe anomaly mechanism is more complex,objective-clanguage control also requires a certain degree of skill, the application is sometimes very easy to create a crash flash back. Use it over and over again.XCodetake the application crash record, parse symbols, usually patience, sometimes also to parse out the call stack in a daze, because the program at the time the internal state is often difficult to see, only to guess.
For the real machine, the log can not be saved, difficult to analyze the problem. Therefore, it is necessary to save the log to the application's Docunment directory and set it as a shared file so that the analysis can be removed.
Import third-party: afnetworkinng
-(void) viewdidload{ [Super Viewdidload]; Afhttprequestoperationmanager *manager = [Afhttprequestoperationmanager manager]; [Manager get:@] Http://mobile.ximalaya.com/m/category_tag_list?category=entertainment&device=iPhone&type =album "Parameters:nil success:^ (afhttprequestoperation *operation, id responseobject) { NSLog (@"%@ ", responseobject); } failure:^ (afhttprequestoperation *operation, Nserror *error) { NSLog (@ "%@", [Error localizeddescription]); }]; }
write a category to it: FOUNDATION+LOG.M
#import <Foundation/Foundation.h> @implementation nsdictionary (Log)//+ (void) load//{//NSLog (@ "11");//}-( NSString *) Descriptionwithlocale: (ID) locale{nsmutablestring *str = [nsmutablestring string]; [str appendstring:@ "{\ n"]; [Self enumeratekeysandobjectsusingblock:^ (ID key, id obj, BOOL *stop) {[str appendformat:@ ' \t%@ =%@, \ n ', key, obj]; }]; [Str appendstring:@ "}"]; Delete the last one, nsrange range = [str rangeofstring:@], "Options:nsbackwardssearch"; [Str Deletecharactersinrange:range]; return str;} @end @implementation Nsarray (Log)-(NSString *) Descriptionwithlocale: (ID) locale{nsmutablestring *str = [NSMutableStri ng string]; [str appendstring:@ "[\ n"]; [Self enumerateobjectsusingblock:^ (id obj, Nsuinteger idx, BOOL *stop) {[str appendformat:@ "\t\t%@,\n", obj]; }]; [Str appendstring:@ "]"]; Delete the last one, nsrange range = [str rangeofstring:@], "Options:nsbackwardssearch"; [Str deLetecharactersinrange:range]; return str;} @end
Final effect:
Tips: IOS-Convert console log log to output as a text file
1. Create a function in APPDELEGATE.M to implement the following block of code:-(void) redirectnslogtodocumentfolder{ nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); NSString *documentdirectory = [Paths objectatindex:0]; NSString *filename = [NSString stringwithformat:@ "MrNSLog.txt"];//note not nsdata! NSString *logfilepath = [Documentdirectory stringbyappendingpathcomponent:filename]; First delete the existing file nsfilemanager *defaultmanager = [Nsfilemanager Defaultmanager]; [Defaultmanager Removeitematpath:logfilepath Error:nil]; Enter log into file freopen ([LogFilePath cstringusingencoding:nsasciistringencoding], "A +", stdout); Freopen ([LogFilePath cstringusingencoding:nsasciistringencoding], "A +", stderr);} 2. Call in didfinishlaunchingwithoptions: [Self redirectnslogtodocumentfolder];
Finally, configure the shared folder:
in the application'sInfo.plistfiles are addeduifilesharingenabledkey and set the key value toYES. Place the files you want to share in the application'sDocumentsdirectory. Once the device is plugged into the user's computer,ITunes9.1it will be in the selected device'sAppsthe label displays aFile Sharingarea. The user can then add files to the directory or move the files to the desktop computer. If the application supports file sharing, when the file is added to theDocumentsdirectory, the application should be able to identify and respond appropriately. For example, an application can display the contents of a new file on the interface. Do not present a list of directories to the user and ask them what they want to do with the file.
daily update concerns :http://weibo.com/hanjunqiang Sina Weibo
<pheiti sc= "Light" = "" >
Technical summary of enhanced log output development in iOS