Showing posts with label debug. Show all posts
Showing posts with label debug. Show all posts

Tuesday, June 5, 2012

CoreData and NSCocoaErrorDomain Code 1570

Seems like iOS CoreData doesn't like non-existing values i.e. "nil".

Didn't realize at first that something was wrong, because a) I wasn't very familiar with Coredata, just inherited the code to be upgraded and b) I created my own caching on top of CoreData to compensate some issues with CoreData. Then found this error buried deep into console logs:
CoreData Error Domain=NSCocoaErrorDomain Code=1570 "The operation couldn’t be completed. (Cocoa error 1570.)

Tuesday, February 28, 2012

Could not load the image referenced from a nib in the bundle with identifier

Just make sure your files are where you (your project file) thinks they are.
myApp[12345:678] Could not load the "image.png" image referenced from a nib in the bundle with identifier "com.company.app"
Check for filenames in red (at left), indicating that somehow some file became unknown. Maybe you were moving files around in Finder, were you? Of course you were, you silly bugger!

Saturday, January 7, 2012

Always Test in Real - Not Just Crappy - User Device

Memory related defects can be hard to debug, therefore I usually force automatic system "out of memory" notifications. That makes sure I have no other choice, but to handle potential OOM issues from the start. Otherwise the app won't run. Clever, right?

And that's the problem. Potential OOM issues. Did you notice that "potential" keyword?

Thursday, November 24, 2011

Console On Device 1.0 Now Available in App Store

I am happy to tell that second of my old three apps is finally available in App Store:


It's mainly a developer utility to check iOS console output within your device, without a computer. However many released apps write debug data into console, so occasional users can use it to check what's going on under the iOS hood - even whether some app really crashed or not (check "ReportCrash").

So why did I write it? Because I needed something like that in a real customer project, but couldn't find. Here's the story, without any names:

Thursday, October 27, 2011

How to Handle HTTP Headers in iOS4 and iOS5

One of several minor incompatibilities between iOS4 and iOS5 is the way how HTTP headers are reported. The difference is in the capitalization and white-space handling:
iOS4: @"Myapp-Sampleheader ";
iOS5: @"MyApp-SampleHeader";
Once you figure out this is the problem, the fix is quite easy. Here is a generic routine to handle both cases at the same time:

Tuesday, September 27, 2011

declaration of 'struct sockaddr_in' will not be visible outside of this function

Everybody and their mom has own modified Reachability code and none are compatible. Yet another fix to the "default" code, in case you see this kind of warning or error (no-warnings policy):
Reachability.h: error: declaration of 'struct sockaddr_in' will not be visible outside of this function [-Werror,3]
Fix is easy, just add this:
#import <netinet/in.h>
Hope Apple would pull together all "fixes" and update the Reachability master version for all of us.

Monday, September 19, 2011

Conversion specifies type 'unsigned int' but the argument has type 'unsigned long long'

Been quite busy with maintenance issues lately (close to release), no time to blog. So here's just a small tip until I get into more interesting new development tasks:
unsigned long long bodyLen =
  (unsigned long long) [self.bodyPrefix length] +
  // ALAsset defaultRepresentation size returns (long long)
  (unsigned long long) fileSize +
  (unsigned long long) [self.bodySuffix length];
DLog(@"Total data size to send: %llu", bodyLen);
[request setValue:[NSString stringWithFormat:@"%llu", bodyLength] forHTTPHeaderField:@"Content-Length"];
In case you missed, the "printf" parameter to display unsigned long long is %llu...

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?

Thursday, June 30, 2011

How to View HTML Source Code from UIWebView

While debugging a sudden Facebook iOS library defect (Blank Dialog presented), I needed to check the HTML code received from Facebook server. This is how to do it:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
   NSLog(@"%@",
    [webView stringByEvaluatingJavaScriptFromString:
    @"document.body.innerHTML"]);
}
Let's hope Facebook will quickly fix their faulty server-side code - and next time do better testing before a release...

Friday, June 17, 2011

Why Xcode Can't Find My Connected Device

There are many ways to fail launching an application in your device. This was a new one!

iPhone is running iOS 4.1, but project "Deployment Target" is set to 4.3. As result this project does not show your device in Scheme list. Switch to another project with a compatible deployment target and your device is on the list!

Xcode4 completely failed to help debugging this case, in all possible ways.

Tuesday, June 14, 2011

How to Find Unlocalized Strings

How to make sure you have localized all text strings in your application? You check it manually once - and then change the code. Is everything still localized? Did someone else in team just touch the code?

Fortunately Apple Xcode team comes to rescue!

Sunday, June 5, 2011

NSTimeInterval as Not a Number

This is something very simple. Took me a long time and several attempts to find the answer, most likely because I wasn't able to phrase the question in the correct way.

Anyway - occasionally you are dealing with a NSTimeInterval, which happen to have value Not a Number.

Debugger shows "nan", google search finds "NaN, but the correct answer is "NAN":
if (aTimeInterval == NAN)
{
    // don't use timeInterval
}
Sometimes the most important thing is asking the right questions.

Thursday, May 26, 2011

How to Run Instruments with Real Device

You can start profiling your application by pressing Command-I (that's i like in India). By default Xcode4 Instruments runs on simulator.

When you want to profile on a real device: select at top left corner Scheme popup menu, "Edit Scheme...", Profile MyTest.app and change Build Configuration from Release to Debug.

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!

Monday, April 18, 2011

Operation failed with underlying error 4294956467

Thanx Xcode, that was very informative. I'll fix it right away! Oh wait, what was that...
Failed to launch simulator: Operation failed with underlying error 4294956467.

Friday, April 15, 2011

Initializer Element Is Not Constant


This code might look valid to less experienced iOS developers, but it does give a compiler error "initializer element is not constant":

static NSArray *playState = [NSArray arrayWithObjects:
    @"MPMoviePlaybackStateStopped",
    @"MPMoviePlaybackStatePlaying",
    @"MPMoviePlaybackStatePaused",
    @"MPMoviePlaybackStateInterrupted",
    @"MPMoviePlaybackStateSeekingForward",
    @"MPMoviePlaybackStateSeekingBackward",
    nil];

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: