Wednesday, December 28, 2011

Converting Mac sound files using command line


This can be used for lots of sound types:

    afconvert -f caff -d LEI16 slide.mp3 slide.caf

For more info: Good article, Apple Docs

Saturday, December 17, 2011

Aborting commit: '...' remains in conflict


svn remove --force filenameOrDir
svn resolve --accept=working  filenameOrDir
svn commit

Thursday, December 1, 2011

Xcode 4.2 and iOS 4.2.1

Been getting reports of users with second generation iPod Touch running iOS 4.2.1 having layout and image issues. An Apple employee posted:

The most recent LLVM Compiler has a bug wherein armv6 code that uses CGPoint and CGRect structs can be optimized incorrectly. As a workaround, try compiling your armv6 code with "Compile for Thumb" set to No (or add -mno-thumb to your Other Compiler Flags).

I think this is how you turn off thumb using project settings:


I'll give this a shot and report back.

Update: I got a hold of an iPod Touch 2g running iOS 4.2.1 and found that the change to the optimization setting does indeed fix the issue. Backing out the change reproduced the errors. Whew.

Tuesday, November 29, 2011

Google Analytics and iOS

Using Google Analytics to monitor how user's interact with iPhone and iPad apps has been enlightening. Google makes it easy to create a dashboard to quickly grok how an app is being used. It's very easy implement, just add a line of code anywhere you want to record an event. It hasn't introduced any issues (e.g. memory, app approval) in the three apps I've shipped it with. You can create unique web based dashboards for each app you wish to monitor.

Google's latest beta lets you monitor apps in real time - this is SO cool. You can see how many people are currently using an app, where they are in the app, if they are new or returning, and monitor page views in real time. Google provides a map of the world that shows each time a user starts using your app, you can even use Google Earth to spin the globe and highlight the location of each time a user starts to use your app. Some locations have a lot more users than sales, but that's another issue...

armv6

The iPhone, iPhone 3G, first and second generation iPod touch have CPUs that only support the armv6 instruction set. Xcode 4.2 no longer supports armv6 by default. Xcode 4.2 no longer defaults to supporting iOS 3.x, which accounts for about 7% of our users.


The iPhone 3G S, all iPads, and third-generation iPod touch have processors that support armv7.

Tuesday, November 8, 2011

dyld: Symbol not found: __NSConcreteGlobalBlock

This error occurs in Xcode 4.2 when building for pre iOS 4.0. The fix: Add '-weak_library /usr/lib/libSystem.B.dylib' to Build Settings->Linking->Other Link Flags.

Wednesday, February 23, 2011

NSStringToUIColor with alpha

+(UIColor*)toUIColor:(NSString*)hexColorString {
unsigned int c;
if ([hexColorString characterAtIndex:0] == '#') {
[[NSScanner scannerWithString:[hexColorString substringFromIndex:1]] scanHexInt:&c];
} else {
[[NSScanner scannerWithString:hexColorString] scanHexInt:&c];
}
if([hexColorString length] > 7) {
return [UIColor colorWithRed:((c & 0xff000000) >> 24)/255.0 green:((c & 0xff0000) >> 16)/255.0 blue:((c & 0xff00) >> 8)/255.0 alpha:(c & 0xff)/255.0];
}
return [UIColor colorWithRed:((c & 0xff0000) >> 16)/255.0 green:((c & 0xff00) >> 8)/255.0 blue:(c & 0xff)/255.0 alpha:1.0];
}

[Color toUIColor:#001122];
[Color toUIColor:#001122aa];

Elapsed time

NSDate *startTime = [NSDate date];
...
NSLog(@"Elapsed time: %f", -[startTime timeIntervalSinceNow]);

Saturday, February 19, 2011

Recursively removing XCode build directories before SVN import, commit, or add

In Terminal, cd to the repository directory to be checked into SVN

rm -rf `find . -type d -name build`


This will remove all the build directories in all the sub directories e.g. when trunk contains multiple projects.

Checking iOS version at runtime

@interface DeviceUtil : NSObject {
}
+(BOOL)osVersionSupported:(NSString*)version;
@end


#import "DeviceUtil.h"

@implementation DeviceUtil

//    e.g. [DeviceUtil osVersionSupported:@"4.1"]
+(BOOL)osVersionSupported:(NSString*)version {
    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    BOOL osVersionSupported = ([currSysVer
            compare:version
            options:NSNumericSearch] != NSOrderedAscending);
    return osVersionSupported;
}

@end

#warning #error

#warning
The directive #warning is similar to #error, however the preprocessor doesn’t stop when it finds this directive, it simply displays the message to the console and keeps on with the task at hand. One common use of #warning is to display information regarding deprecated code:

#warning : This method is deprecated, use someNewMethod instead

#error
When the preprocessor runs into the #error directive, it will write an error to the console and generate a compile time error. You can also include a text string which is displayed as an error message.

#error : Change this value to your Flickr key
NSString* const FlickrAPIKey = @"your-key-here";


See full article