Tuesday, December 27, 2011

How to Autogenerate App Version Number from GIT

Application needs a version number, naturally. It's publicly used to identify, which version customer is using (and reporting bugs about).

However there is a very important technical reason to take good care of version number: if you want to update application, the new version number must be bigger than the old one. Sounds easy, yet again...

Let's check the documentation:

Thursday, December 8, 2011

How to Sort NSDictionary

Let's get this straight: you cannot sort NSDictionary.

Dictionary is a collection of keys and their objects without an order, therefore you cannot change that non-existing order. You can sort only array data types, since they are basically ordered lists.

There are still good news. You can get all keys from any dictionary as an array and sort them. Usually this is enough.

Tuesday, November 29, 2011

When NOT to Release Your Application

Regardless of all "release early, release often" and "fail early, fail often" talk, there really are moments, when you SHOULD NOT RELEASE your new application.

This could be a trick question, but it's not. Just another hard lessons learned, another strike by faceless market powers. The answer is Thanksgiving, of course.

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:

Wednesday, November 16, 2011

Releasing Console On Device - Lessons Learned

Trying to make my third release, an application called "Console On Device". Learned some new things - and old ones, too.

First of all, application name was already reserved. I did extensive research and tough name planning, when starting to design this app - in February 2011. Surprisingly at November 2011 someone else had already released an app with "my" name!

Lesson learned: I could have created iTunes Connect app record right away to reserve the name. However in this case luck was on my side: I found a new better name!

Tuesday, November 1, 2011

Rise and Fall of FontType in App Store

It's three weeks since release of FontType, my first app under my own name (actually Jomnius). It's been ... interesting times. Didn't expect big sales, but hoped to get at least a few users. Nope.

Some comments and suggestions for update. None. Bug reports. Nada. Hello, anyone there?

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:

Monday, October 24, 2011

Invalid attempt to access ALAssetPrivate past the lifetime of its owning ALAssetsLibrary

Trying to upload hundreds of images from device, but application occasionally crashes with this error note:
invalid attempt to access ALAssetPrivate past the lifetime of its owning ALAssetsLibrary
Basically it means what it says. Library was closed before reading the image data was completed. As result upload failed due missing or too short data. ALAssetsLibrary Class Reference says:

Sunday, October 16, 2011

Cocoaheads Helsinki October 2011

Cocoaheads Helsinki meetup was last Thursday at MK&C office, rigth at central Helsinki tourist district. Good location, easy to access, international atmosphere even before you entered the office.

There was about 10 persons present and the whole meetup was quite informal. General techie smalltalk, comparing iOS5 update war stories, refreshments, presentations. Fun.

Saturday, October 15, 2011

New Fonts in iOS 5.0 - and Some Missing

Apple iOS 5.0 was released few days ago and installation was rather hard. It's still not complete, since I had 500+ apps and restore from iOS 4.3.5 backup was about a total failure. Enough of that, waiting for iOS 5.1 release rather soon.

Let's look at fonts. Yes, with pictures!

iOS 5.0 was a huge update in many ways and one of them is built-in font selection. For the first time ever, iPhone and iPad have exactly the same fonts!

Thursday, October 13, 2011

How to Update iPhone3GS to iOS5

Updating iPhone 3GS to iOS5 was not an easy thing to do:
  • Removed 6GB+ stuff from the device: apps, videos, books, music
  • Cleared 20GB free disk space at MacBook Pro
  • Installed all Mac OS updates released AFTER iTunes update
  • Reboot
  • Try to update for umpteenth time
That took about 3 hours on late Wednesday night and 2 hours on early Thursday morning with 5 hours sleep in between.

Pro tip: make sure you don't have any wake up alarms setup to tricker during update! It's e-x-t-r-e-m-e-l-y annoying to listen to the alarm, while not being able to shut it down. I had to skip Apple ID phase just to SHUT-THE-FC*K-UP clock alarm. Don't really care what did I screw up.

It was either that or introducing iPhone to my fine-tune hammer. Very close call (after all those hours wasted to fail with update).

Tuesday, October 11, 2011

FontType 1.0 Now Available in App Store

After lots of sleepless nights and countless redesings I am happy to tell that first of my three apps is finally available in App Store:

It's a small and nice "font viewer" application. Got several reasons to write it, so many that I want to list them:

Friday, October 7, 2011

Remembering Steve Jobs 1955 - 2011

One day after Steve Jobs died in cancer... What is there to say. How to find motivation to go on, how to get back in the zone. Where is the excitement and enthusiasm now?
We don’t get a chance to do that many things, and every one should be really excellent. Because this is our life.

Life is brief, and then you die, you know? And we’ve all chosen to do this with our lives. So it better be damn good. It better be worth it.
Steve Jobs
Thanx, Steve. For everything.

Tuesday, October 4, 2011

Application Failed Codesign Verification

Submission to App Store wasn't as easy as I thought in previous blog. Not really surprised, but this problem was tough to solve. Not tough as in hard to fix, but as hard to figure out:
Application failed codesign verification.  The signature was invalid, or it was not signed with an Apple submission certificate. (-19011)

Monday, October 3, 2011

Application Validation Problems

Tried all weekend to make a release, these were the last issues to be solved:
warning: Icon specified in the Info.plist not found under the top level app wrapper: Icon-SMall@2x.png (-19007)

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.

Wednesday, September 21, 2011

How to Create Custom Background for UINavigationBar

Needed a custom background for UINavigationBar (pre-iOS5). First tried placing an UIImageView under "Black Translucent" UINavigationBar, but there were some problems:

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?

Friday, August 5, 2011

Sending 'const NSString *' to parameter of type 'NSString *' discards qualifiers

This is a constant pointer to a NSString object, which btw is immutable by SDK. Pointer cannot be changed to point anywhere else. That was most likely the very reason why you're using const in the first place. This can be used in e.g. isEqualToString without compiler warning.

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
    [webView stringByEvaluatingJavaScriptFromString:
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!

Monday, June 13, 2011

CocoaHeads Helsinki #2

The second CocoaHeads Helsinki meetup was held last Thursday 9 June 2011 at MK&C office. There was only about 10 persons present, since WWDC was going on elsewhere.

We still had good time, nobody missed WWDC. Yep :)

Thursday, June 9, 2011

Testing TestFlight

Started last night beta testing my few small but simple applications. In past I've done ad hoc releases and distribution manually and was not really looking forward to do it again.

Then I was told about TestFlight. It's beatiful. It's user-friendly. It works. And then some more!

Monday, June 6, 2011

How to Clear Project Build Results

You have a project with several targets, of which at least one fails. You can see this at Xcode4 iTunes-styled toolbar info window at top.

Except that The Target that you just build was just fine. No warnings, no errors. Xcode4 still tells something went wrong!

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.

Friday, May 27, 2011

Three Applications to Be Released

There are still some minor open issues, like icons, colors, title and writing webpages. Otherwise everything is just fine :) Well, besides releasing the apps, I mean. But that day is getting closer.

"Time" which shows current time and that's pretty much it. Lean, clean and simple on purpose, but I fear it might be too simple for Apple. Might have to add something to get approved, unfortunately.

"Font" application, since I just love fonts. There must be 50 fonts applications in App Store already, but wanted to do my own. Looks good, got some nice features and I have a list of things to add.

"Log" application to display in-device NSLog output. Needed this kind of application in "real work", but couldn't find any with requires features. The first release will be simple on purpose, need some feedback to decide what to add in next version. Too many choises to be made based only on single person's (me) feedback.

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.

Why Would You Ever Need a Fax

When you want to register a new company into Apple Developer Program, you need to fax them some documents.


Remember that ancient thingie from history classes in school? Or tech museums? Yes, that's the one. Fax.

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

How to Change UIView Size in Interface Builder

When you create a new UIView XIB in Interface Builder, it is by default full-screen. Width and height cannot be changed, they are dimmed out. What to do?

Switch to Simulated Metrics and change "Status Bar" from default (gray) to None. Now you can edit the size!

First time this was difficult to discover, second time I kind of recalled what to do and now it's all so plain obvious :)

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

No New Fonts in iOS 4.3.2 Either

While I still remember... Yes, I checked iOS 4.3.2 update. There are no new fonts, when compared to iPhone or iPad running iOS 4.3 or 4.3.1. Don't have iPad2, but I doubt there's any new fonts in that device alone.

Sometimes no news is the news.

Previously released iOS 4.3 has new Noteworthy font and there is also a complete list of iOS 4.2.1 fonts. I do have locally more complete table of fonts, should make it public.

Got a new feature for my fonts application: autocheck whether there are any new fonts. Invest a day worth of development to save 15 minutes of boring manual work!

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:

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:

Monday, April 11, 2011

Easy Way to Create Settings View

Most applications need settings or at least a way to display version number. In theory it's very simple: just show a short list with a few hardcoded rows. It could be difficult, but since "settings" is such a common use case, Apple iOS SDK offers special support. It's not quite perfect, so let's check the possibilities.

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, April 7, 2011

How to Reset MPMoviePlayer Timeline

When you stream a video (HTTP Live Streaming) over network till finish, the timeline might show there's still a few seconds missing. The problem is that the initial video duration is an estimation, not the exact video length.

There is a system callback, which is called when real video duration is known:

Wednesday, April 6, 2011

MPMoviePlayer Tips

Trying to make MPMoviePlayer do "things" it doesn't really want to. Finding lots of tips, saving here as reference. Yes, it was a long day. Too many tips to be remembered tomorrow.

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]:

Wednesday, March 30, 2011

How to Change UITextView Background Color

You have UIView, which contains UITextView with some text. This is how to change UITextView background color:
self.view.opaque = YES;
self.view.backgroundColor = [UIColor yellowColor];
self.textView.opaque = NO;
self.textView.backgroundColor = [UIColor clearColor];
self.textView.textColor = [UIColor orangeColor];
Not what I was looking for, but might as well write down, looks useful enough. Another tool in the toolbox, even though everything still looks like a nail.

Sunday, March 27, 2011

Hide UITableView Empty Cell Separator Lines

Plain UITableView displays cell separator lines, when table is empty or has only a few real cells. This is the default behaviour - and it is good. You should not change it.

But sometimes it looks a bit too weird. When your cells have different heights, all empty cells following the last real one will use last cell's height. If this changes at every table refresh, the "jumping" empty cells start annoying users. Or at least developers.

No New Fonts in iOS 4.3.1

Just checked iOS 4.3.1 update. There are no new fonts, when compared to iPhone or iPad running iOS 4.3. Don't have iPad2, but I doubt there's any new fonts in that device alone.

Sometimes no news is the news.

Previously released iOS 4.3 has new Noteworthy font and there is also a complete list of iOS 4.2.1 fonts.

Am I obsessed with fonts? Just a little bit :)

Saturday, March 26, 2011

How to Define Custom backBarButtonItem

When you push a UIViewController into navigation stack, there is a default "back" button with the title of previous view. Sometimes the title is too long or text is not quite right. Then you need to define your own.

Fortunately it's easy. The problem is where to do it.

Wednesday, March 23, 2011

Request for member 'item' in something not a structure or union

There are several ways how you can get this compiler error - and here's another one. With one way to fix it.

First setup everything:
@interface MyPlayer : MPMoviePlayerViewController
UIView *parentView;
@property (nonatomic, retain) UIView *parentView;

@interface MyView : UIView
MyPlayer *myPlayer;
This doesn't work, compiler error:
self.myPlayer = [[MyPlayer alloc] init];
self.myPlayer.parentView = self;
This is ok:
MyPlayer *player = [[MyPlayer alloc] init];
player.parentView = self;
self.myPlayer = player;
[player release];
Divide and conquer... If this didn't help you, remember to check that you import correct header files.

Wednesday, March 16, 2011

How to Debug Webtrends.framework Linker Problems

You are trying to integrate Webtrends Analytics library as Webtrends.framework into your application and linker fails with lots of undefined symbols:

Monday, March 14, 2011

How to Copy Current Toolbar to Next NavigationController

Your application is based on idea of lists, where you can navigate deeper into sublists and then back again. There is a common set of actions, which you want to launch from toolbar at the bottom of each screen.

Sounds easy, except you need to define the toolbar separately for each UIViewController while navigating deeper into lists. That should be easier, right? Try this: