Summary of enhanced log output Development Technology in iOS

Source: Internet
Author: User

Summary of enhanced log output Development Technology in iOS

For those engineers who are working on backend development, it is a matter of course to read the LOG to solve the Bug. However, many of the mobile application development engineers I have come into contact with do not have this idea, when you check bugs, you always try to reproduce them again and debug them, especially for bugs that are not easy to reproduce. In addition, the exception mechanism of iOS is complicated, and the language control of Objective-C also requires some skill. The applications made are sometimes prone to crash and crash. Using XCode to retrieve application crash records and parse symbols over and over again is often annoying. Sometimes it is still in a daze for the parsed call stack, because the internal status of the program is often hard to understand, you can only guess.

For real machines, logs cannot be saved, so it is difficult to analyze the problem. Therefore, it is necessary to save the log to the Docunment directory of the application and set it to a shared file for analysis.

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 for it: Foundation + Log. m

 

 

# Import
 
  
@ Implementation NSDictionary (Log) // + (void) load // {// NSLog (@ 11); //}-(NSString *) descriptionWithLocale :( id) locale {NSMutableString * str = [NSMutableString string]; [str appendString :@ {]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id obj, BOOL * stop) {[str appendFormat: @ % @ = % @, key, obj];}]; [str appendString :@}]; // Delete the last one, with the value of [str rangeOfString :@, options: NSBackwardsSearch]; [str deleteCharactersInRange: range]; return str ;}@ end @ implementation NSArray (Log)-(NSString *) descriptionWithLocale :( id) locale {NSMutableString * str = [NSMutableString string]; [str appendString: @ []; [self enumerateObjectsUsingBlock: ^ (id obj, NSUInteger idx, BOOL * stop) {[appstr endformat: @ % @, obj];}]; [str appendString: @]; // Delete the last one, in the format of [str rangeOfString: @, options: NSBackwardsSearch]; [str deleteCharactersInRange: range]; return str ;}@ end
 

 

 

Final effect:


 

 

Tip: iOS-convert the console Log into a text file

 

1. in AppDelegate. create a function in m to implement the following code blocks:-(void) redirectNSlogToDocumentFolder {NSArray * paths = require (NSDocumentDirectory, NSUserDomainMask, YES); NSString * documentDirectory = [paths objectAtIndex: 0]; NSString * fileName = [NSString stringWithFormat: @MrNSLog.txt]; // note that it is not NSData! NSString * logFilePath = [documentDirectory stringByAppendingPathComponent: fileName]; // delete an existing file NSFileManager * defaultManager = [NSFileManager defaultManager]; [defaultManager removeItemAtPath: logFilePath error: nil]; // input the log to the file freopen ([logFilePath cStringUsingEncoding: encoding], a +, stdout); freopen ([logFilePath cStringUsingEncoding: encoding], a +, stderr);} 2. call [self redirectNSlogToDocumentFolder] In didfinishlaunchingwitexceptions;
Finally, configure the Shared Folder:

 

Add the UIFileSharingEnabled key to the Info. plist file of the application, and set the key value to YES. Place the files you want to share in the Documents Files directory of the application. Once the device is inserted into your computer, iTunes9.1 displays a File Sharing area in the Apps tab of the selected device. After that, you can add files to the directory or move the files to the desktop. If the application supports file sharing, after the file is added to the Documents directory, the application should be able to identify and make appropriate responses. For example, an application can display the content of a new file on the interface. Do not display the file list of the directory to users and ask them what operations they want to perform on the file.


 

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.