Showing posts with label NSLog. Show all posts
Showing posts with label NSLog. Show all posts

Wednesday, September 7, 2011

How to Do Dynamic Debug Logging in Released Application

Remote debugging can be really difficult, especially for released applications. You can't send ad hoc releases to everyone! Would love that, with service like TestFlight, but normal Apple iOS developer account can register only max 100 devices.

So what can you do?

Wednesday, May 18, 2011

Some retainCount Love

When you design, you're dreaming what could happen. When you code, you're experimenting what can happen. When you debug, you're learning what is happening.

Tuesday, May 17, 2011

Multiline NSLog Output and Other Debugging Tips

While debugging mysterious memory management related crashes, I needed to write quite a lot of things into log. So much that log became unreadable.

Wednesday, May 11, 2011

Visual UI Debugging

Sometimes you need to debug location of objects. This can be difficult, when those objects are transparent or have same color as the background.

Wednesday, April 20, 2011

Easy Way to Debug UIView Hierarchy

Do you want to see complete view hierarchy for debugging purposes? There is an easy way to do it, provided by Apple - totally unofficially!

Actually official documentation says it's undocumented and not supported. No problem with that. Very kind of Apple, good developer service!

Wednesday, April 13, 2011

Better Debug for CGRect, CGPoint and CGSize

Can't remember how many times I've wanted to debug what is the size of a frame. Can't remember how many times I've written x and y coordinates, followed by width and height, to console log.

All wasted time and effort, while I could have been doing something more productive! Live and learn: just found out that iOS SDK contains helper routines for that task:

Friday, April 8, 2011

Autoreleased with No Pool in Place - Just Leaking

When you perform an operation in another thread, place EVERYTHING inside your thread specific autorelease pool. That includes writing debug messages in log as well as sending notifications. Otherwise you will leak memory.

Thursday, March 31, 2011

Beware Using [UIScreen mainScreen].bounds

Found and fixed another device rotation defect, was using wrong bounds to check screen size. Should have used self.tableView instead of [UIScreen mainScreen]:

Monday, February 21, 2011

How to Find MFMailComposeViewController Email Addresses

One of the missing iOS APIs is a way to find out whom did user send email to. Otherwise MFMailComposeViewController is excellent: easy to setup, easy to launch, easy to use and easy to close. You just have no idea what user was doing with it!

I really needed to know who were email recipients. There are several good reasons for this and I just had one of those. So it was time to do some experimenting!

Monday, February 14, 2011

UISearchDisplayController with No Results

Don't know what it is, but I just can't make UISearchDisplayDelegate shouldReloadTableForSearchString method work the way I read the documentation:
You might implement this method if you want to perform an asynchronous search. You would initiate the search in this method, then return NO. You would reload the table when you have results.

Monday, February 7, 2011

UITableView with Custom Cell Height

I'm writing an application, where startup view contains UITableView - which seemed pretty slow. Basic version is not too bad, but when using a custom UITableViewCell created from XIB, it became totally unusable.

Time to debug whether Interface Builder's XIB makes things slow!

Wednesday, January 26, 2011

Process 1018 Exceeded 500 Log Message Per Second Limit

Just found this new error code from iPhone console log:
Tue Jan 25 15:52:19 unknown App Name[1018] <Error>: *** process 1018 exceeded 500 log message per second limit  -  remaining messages this second discarded ***

Friday, January 21, 2011

What is Inside UIImagePickerControllerMediaMetadata

Been debugging UIImagePickerController too many times, so it's time for some tips. The most easy way to see what's in there somewhere. Also including a sample output.

Wednesday, January 5, 2011

How to Debug NSURLConnection HTTP Headers

When you are connected to a server somewhere in internet and something doesn't seem to be quite right, what would you do?

That's right, check HTTP headers from server response:

Monday, December 20, 2010

How to Detect iOS Version in Code

Bumbed into a case where code crashed iOS 4.0.2, but worked with iOS 4.2. Since crash happened because of missing NSString *const, couldn't use respondsToSelector to choose, which code to run. Decided to simply check what is current iOS version:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version > 4.0)
{
    // iOS 4.2 specific code
}
else
{
    // iOS 4.0.2 specific code
}
Please note how three part version number gets converted to float:
NSString *s = [[UIDevice currentDevice] systemVersion];
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
NSLog(@"Version: %@ and %f", s, version);
NSLog(@"Version: %@ and %f", @"3.1.3", [@"3.1.3" floatValue]);

Version: 4.0.2 and 4.000000
Version: 3.1.3 and 3.100000
I'm not really happy with the solution, but it works. Can live with that.

Update:

Always run code in real device! My development device iPhone4 with iOS 4.1 returns "4.1" as string, but that gives 4.0999999 as float value !!!

Friday, December 10, 2010

Where is iPhone Simulator NSTemporaryDirectory

Sometimes I need to save temporary files. The problem is cleaning up afterwards: application might crash during debug sessions leaving files, which are accessed on following launch thus messing up normal expected application behaviour.

iOS provides application specific temporary folder. The benefit in using this is that even if the worst case happens and your app fails to clean up temporary files for some reason (try to view 65 MB image, for example), application temporary folder is automatically cleaned out every 3 days. Your application is thus not able to leave behind "zombie" files, which would fill up device harddisk until all available space is used!

Thursday, July 15, 2010

Random Crashes while Debugging - by Debugging

Sometimes the problem is that there is no problem. Trying to debug it more can make the situation even worse - while the real problem was caused by debugging in the first place!

If you have mysterious freezes while debugging UITableView, try reducing the amount of logging. Fixed one such problem by NOT sending any NSLog messages from cellForRowAtIndexPath delegate callback. Seems like too many log messages messed up internal iOS timing.

Wonder how many times I have to re-iLearn this iLesson!

Tuesday, January 26, 2010

How to Debug Currently Used Thread in iPhone

Sometimes everything you code is correct, just doesn't work all the time. Problem might be that occasionally your UI update related code is called from non-main thread. This is how to debug which thread you're using:

#include <pthread.h>

- (void)myFunction
{
NSLog(@"Thread (%d)",
pthread_mach_thread_np(pthread_self()));
}