Thursday, August 26, 2010

How to Remove Unused Parameter Warning

No Warnings Policy requires sometimes forcing a compiler warning to be ignored. One such case is when you are given a function you absolutely must use, but don't need the parameters:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
#pragma unused(application)
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}
There are several ways to ignore warnings, I found #pragma to be a clean solution.

Wednesday, August 25, 2010

grep Regular Expressions and Internationalization

Wanted to find all meaningful text strings in an iPhone project, preparing for a proper internationalization:
grep -r '@"' * |grep -v -E 'NSAssert|NSLog|@""'
Forgotten this so many times, it's better to write it down: how to search for several patterns at the same time using grep on Mac OS X command line (bash shell). Could use also command line parameter -P (Perl Regular Expression) in this case, but -E (Extended Regular Expression) is more generic.

...so why wasn't internationalization done in the first place, when things were still simple? Because in certain kind of experimental projects you need to get results fast and early to decide whether it's worth continuing at all. If available time is used for "doing things right", there won't be any (good enough) results and The Project Will Be Terminated.

Just a question when do you want to invest your time: early or later. Have to pay the price anyway. Usually the longer you wait, the higher the price will be. On the other hand at that time you might have afford it.

Multiple Info.plist files and UIApplicationExitsOnSuspend

I have three Info.plist files: one for release (Info.plist), second for release testing (Info_release.plist) and third for testing (Info_test.plist).

In other words, I generate three separate applications from same sources so that all can be installed in a device at the same time. Therefore the content of plist files are identical, except CFBundleIconFile and CFBundleIdentifier.

When looking at Info.plist in XCode I can see "Application does not run in backgr" with a checkbox, while the two other plist files show UIApplicationExitsOnSuspend. Open all three files as source code or text and they contain exactly the same code:
<key>UIApplicationExitsOnSuspend</key>
<true/>
Weird... still everything seems to work ok. Just a note. Btw official documentation is available here.

Tuesday, August 24, 2010

How to Show Text Left and Right in UIWebView

When you need to show text on same line at left and right in UIWebView, this is one way:
NSString *myHtml = [NSString stringWithFormat:
    @"<html><body>"
    "<span style='float:left'>%@</span>"
    "<span style='float:right'>%@</span>"
    @"</body></html>",
    @"I'm left", @"I'm right"];
   
[self.cellWebView loadHTMLString:myHtml baseURL:nil];
Can't use div, since it seems to force a linebreak by default.

Monday, August 23, 2010

How to Get Share Buttons into Blogger

Blogger supports Share Buttons - officially.

Unofficially you might have to do some manual tweaking to make it actually work: Solution: Blogger Share Buttons not showing up? and reverse style.

Thursday, July 22, 2010

How to Solve Ad Hoc release "value not permitted by a provisioning profile"

Ever since I submitted an application to App Store I've had lots of problems creating Ad Hoc release. Though first fix was simple, it's not a complete solution.

Error messages are:

Thu Jul 22 11:46:34 jouni-iDevice installd[643] : entitlement 'keychain-access-groups' has value not permitted by a provisioning profile

Thu Jul 22 11:46:34 jouni-iDevice installd[643] : entitlement 'application-identifier' has value not permitted by a provisioning profile
...
Thu Jul 22 11:47:06 jouni-iDevice SpringBoard[28] : Application 'Zattr' exited abnormally with signal 11: Segmentation fault

This time the solution was found in TUAW article "devsugar: A better way to share ad-hoc builds".

Summary: instead of normal Build use Build and Archive, find your application, find the last date, press Share Application button and - The Critical Phase - verify your identity is your Ad Hoc Distribution Provisioning Profile. Save locally and install e.g. via iPhone Configuration Utility.

...suspect Ad Hoc release problem is caused by having two different provisioning profile files using same application id. I generate three applications (development, release test, public) from same sources with some compile time flags and different provisioning profiles and app ids. Guess code signing identities got mixed.

Warning - No location found for "MyFile.m:42"

Debugger Console might show you something like this:
Warning - No location found for "GuestLoginNote.m:33"
This is most likely a forgotten breakpoint in a file which doesn't exist any more. To get rid of the warning, please go to XCode menu Run - Show - Breakpoints. Locate the problem breakpoint and delete it.