Tuesday, December 21, 2010

Localizing images

I sent version 1.0 of Way of Life to the App Store supporting only English. Now working on the 1.1 update with support for German, Korean, Danish and Polish I had to localize a few images too (screenshots in the tips section). However, UIImage doesn't load the localized version of the image unless you clean your target, i.e., delete the original images that are on the same directory level as the .lproj-folders (that "Make Localizable" creates). For localization of images you have to make sure those images are not present for UIImage not to take the first and the best image. I guess it has a search order where it first looks in the directory for "some_image.png" and if it doesn't find it looks in "users_selected_language.lproj" folder for "some_image.png".
The problem with this is that when the 1.1 update comes out current users will not see the localized version of the images even though they are there. I could make a method that deleted the files - I know!

Daily advice: use "Make Localizable" on images you think you might have to localize in a future update.

Saturday, December 18, 2010

Super fast way of integrating Twitter into your app

NSString *stringURL = @"twitter://post?message=check out this cool lifestyle app http://itunes.com/apps/wayoflife";


NSString *escapedStringURL = [stringURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]


NSURL *url = [NSURL URLWithString:escapedStringURL];


[[UIApplication sharedApplication] openURL:url];


----


Of course it requires that the user has Twitter installed on his/her phone to handle this URL.


Friday, December 17, 2010

Loading localized strings into an NSDictionary

Get the path to the strings file.


NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"];


pathToFile now points to the correct localization of the Localizable.strings according to user prefs.


NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile: pathToFile];

Wednesday, December 15, 2010

Using filename extension with the UIImage imageNamed method

From iOS 4 you are not required to specify the filename extension when using UIImage, that is, you can set the image like this:

UIImage *testImage = [UIImage imageNamed: "anImageWithoutExt"];

and UIImage will figure out what to use from what ever is present in the bundle.

However, if your deployment target is older than iOS4 then your UIImage doesn't load the resource and so returns nil when the app is run on pre-iOS4.

Recommendation: use a filename extension if you deployment target OS is below iOS 4.