Private API iPhone button creation

This is cool. Use the private API UIGlassButton in the iPhone simulator to create button images. Then import the images in your project and leave the private API call out.

Posted in Apple, Coding | Leave a comment

Used iPhones are still worth big money!

A month or so ago I finally broke down and upgraded our iPhones to 3G, and sold our old ones on Ebay. It worked out well.

Bought – 2 16gb iPhone 3Gs, $300 each + tax & misc AT&T fees.
Sold – 2 8gb first gen iPhones for $330 and $335 – about $20 each for Ebay/Paypal fees and shipping.

So the initial purchase is pretty well canceled out. The new service plan is eligible for corporate discounts, so hopefully my discount will cancel out the more costly monthly bill.

Posted in Apple | Tagged , | Leave a comment

Use NSUserDefaults to persist data between app runs

On the iPhone you generally want your application to start looking like it did when it was last run to give the user the impression your app is ready to pick up where it left off. NSUserDefaults provides an easy way to store your application’s settings between runs. Simply create an instance of NSUserDefaults and give it the key/value pairs you want it to save.

Storing an integer

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger: myIntValue forKey: @"intValueKey"];
[prefs synchronize]; // writes modifications to disk

Reading it back in

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
int myIntValue = [prefs integerForKey: @"intValueKey"];

or more simply

int myIntValue = [[NSUserDefaults standardUserDefaults] integerForKey: @"intValueKey"];

Of course, this would be pretty useless if it only worked for integers. The same basic syntax also works for setObject/objectForKey and some others. Check the documentation for details. I have not tried with complicated compound objects yet, but NSUserDefaults so far I have had success with strings and simple arrays.

Posted in Apple, Coding | Tagged , | Leave a comment

NSNotificationCenter

I just learned about NSNotificationCenter. Any class in a program can send a notification message to the notification center, and all classes can listen to the center and respond to messages that apply to it. It’s kind of like a callback, but really not.

This is part of my code for implementing a custom keyboard in my iPhone app.

To send a notification named “keyboardDone” to all objects in your program.

[[NSNotificationCenter defaultCenter] postNotificationName: @"keyboardDone" object: nil];

To listen for the “keyboardDone” notification and call the “keyboardDoneObserver:” method when it’s received this can be added to your class’ init code.

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyboardDoneObserver:) name: @"keyboardDone" object: nil];

And this is the “keyboardDoneObserver:” method that gets called when notified.

-(void)keyboardDoneObserver: (NSNotification*)notification {
     // do work here
}
Posted in Apple, Coding | Tagged , | 1 Comment

Adding a code beautifier script to Xcode

Xcode’s re-indent command is pretty weak compared to the code reformatting built into other IDEs. It fixes the indentation at the beginning on each line, which makes a huge difference in code readability, but I don’t think it does anything else. In Eclipse and VS I’ve gotten used to being fairly lazy about being consistent with my spacing elsewhere and relying on their built in reformatting to clean it up for me. I wanted to change the way Xcode reformats code, since it’s easier to change tools than to break bad habits.

I spent some time searching for command line code beautifiers that support Objective C and only really found one. Uncrustify is open source, which is pretty fortunate since they don’t have an OS X binary download of the current version. The source download includes the needed project files for Xcode, so compiling your own is easy enough. Just open uncrustify.xcodeproj and compile. You could also download another project, Universal Indent GUI which includes an already compiled Uncrustify executable along with a GUI front end.

After I compiled the executable, I copied it and the defaults.cfg file to a new directory and created a couple user scripts in Xcode to use it. The code for both scripts is identical, just adjust it for the correct paths to the files.

#!/bin/sh
echo -n "%%%{PBXSelection}%%%"
/path/to/uncrustify -q -c /path/to/defaults.cfg
echo -n "%%%{PBXSelection}%%%"

The “Reformat all” script will run Uncrustify on the entire document.

The “Reformat selection” is the same except “Input” is set to “Selection” and “Output” is set to “Replace Selection”.

The defaults.cfg does pretty well with obj-c but isn’t perfect. At least it’s consistent. One of these days I’ll find a better config for it it try fixing it myself.

Posted in Apple, Coding | Tagged , , | 14 Comments

Activating iPhones. Two iPhones – one family plan

Over the weekend my wife and I upgraded our cell phones.
We’ve had a family plan with T-Mobile for several years and had been fairly happy with it. Especially the price, both of our phones combined only cost us about $50/month. Lately we’ve both been having problems with the service, which makes me think T-Mobile is having network problems as opposed to one of us having a bad handset. For the last couple months we would make or receive calls and we would be able to hear the person on the other end but they would not be able to hear us, and like I said, it happened with both of our phones. Friday was the last straw, as I called my wife 4 times and we had problems each time.

So, Sunday we went to the local AT&T store. I would have rather gone to the Apple store but AT&T was closer and gave us an opportunity to look at other phones. Anyway, we bought 2 iPhones, which we activated once we got home. Activation was easy, but there was a little confusion on signing up for the family plan. One of the options in iTunes is to sign up 2 or more phones on a new family plan account. I assumed after I set up the first phone it would prompt me to set up additional phones, but this was wrong. After the first phone was activated there was nothing to tell me what the next step should be, so I plugged in the 2nd phone and selected the family plan option again. About half way through I realized it was going to create another separate account instead of adding the phone to the account I’d just created, so I started over and used the existing customer option to add a phone. I guess I was only a new customer for the first phone, which I suppose is true, but since the option I picked originally said activate multiple phones I assumed it would prompt me for multiple phones. In any case, it only took about 20 minutes to activate my first phone and transfer the number from my old one, and about a half hour for the second including time I wasted trying to figure out what I was doing wrong.

I have not called T-Mobile to cancel my old account. I had logged into their website to view my account information and find my account number prior to moving the phone numbers. After the new phones were fully activated I tried to log into the old account again to look for instructions on cancelling, and could not log in. The web page told me the numbers had been cancelled, so I’m thinking the account closed automatically.

Posted in Apple | 3 Comments

AK Octane chair

Last week I purchased my latest cheap office chair. It’s an AK Designs Octane chair purchased from Best Buy. My experience is that any of the sub-$200 chairs purchased from retail stores will last about two years before the mechanism that allows the chair to rock and turn will wear out to the point that it loudly squeaks when you use it. At $150, I fully expect this chair to be no different.

The good

This chair is just really comfortable. The sides of the back wrap around you so it feels similar to a sports car seat designed to hold you in place while cornering. Also, the back has a bit of a lumbar bump built into it that feels great on the back.

The armrests adjust up and down, side to side, and pivot. I’m not sure if this is useful, or just fun to play with. Either way I like it.

The chair has big, roller blade style, wheels that roll smoothly on a variety of surfaces. They are even pretty good on carpet.

The blue and black color scheme is a perfect match for my blue walled and black furnished home office.

The bad

It’s still a cheap chair that will wear out in a couple years. The mechanism underneath the seat looks almost identical to the ones on all of my previous cheap chairs and nothing like the ones on the professional chairs we use at work.

The tall wheels have a couple side effects. First, the legs that attach the wheels are now a little higher than normal. Achilles tendon height. If you roll it into your heal while sitting it will break skin and hurt. Trust me. Secondly, the taller wheels mean the lowest setting for the seat height in taller than my previous chairs.

Posted in Uncategorized | 19 Comments

Trying Windows Vista

Over the weekend I decided to test Windows Vista on my old PC. The install and hardware support were better than I expected considering the several articles I’ve seen and the coworker who assured me that my nVidia nForce2 motherboard (Abit NF7S) chipset was totally unsupported under Vista.

The install was fairly straightforward. Since I have an MSDN subscription and this is my .NET development machine, I could legally download the Vista ISO from the MSDN download site. The install was straightforward, and while nVidia does not offer drivers that can be downloaded, the NIC was supported in the original install and most of the other hardware worked after a trip to Windows update. The raid controller and one other device were still listed as unknown in device manager, and the audio was labeled as unsupported but moved to the audio section. I don’t have any speakers connected, so I can’t say if it worked or not, but a PCI sound card could always be added if needed. At least the hard drives were running in UDMA mode. Overall the system ran pretty well, and I was able to use the Aero interface.

I installed a few apps. My antivirus program failed to install. Visual Studio 2003 is officially unsupported and this Microsoft KB article didn’t provide a lot of confidence. Office seemed ok. Synergy sort of works but was too annoying to actually use.

A while back I posted about my use of Synergy to share my keyboard and mouse between my iMac and PC. I’ve been very happy with the solution for the last few months with XP on the PC. You can configure Synergy to start at system startup or when you log in, and I use the system startup option so that I can use my Mac keyboard to log into the system. With Vista, Synergy is not able to configure itself to run at system startup. At first I thought this would be my worst annoyance, until I got my first of the famous “cancel or accept” prompts that the Apple commercial spoofs so well. Every time I got the prompt, synergy would quit working and I’d have to use the PC mouse to click accept. Then, after I got rid of the prompt, Synergy wait about five minutes before it would resume working.

After a days worth of exploring Vista, I reinstalled XP.

Posted in Apple, Windows | Leave a comment

New Mac in the house

Yesterday we stopped at CompUSA to look for a new MP3 player for my wife. We are going on a trip in a few weeks and she wanted something cheap to listen to on the flight, and we were thinking of a 2GB Sandisk or something comparable for around $100 or so. The idea of cheap didn’t work out so well, we ended up with a 80GB video iPod and a Macbook Pro. Nice impulse buy, huh? We had been planning on her buying a new laptop soon anyways, and she’d been leaning towards switching to a Mac since I’ve had the iMac for a few months. They currently have 5% off of all Apple products, and I was able to get some extra off of an open box laptop, so we ended up a little cheaper then if we had used the corporate purchase plan at the Apple store.

Posted in Apple | Leave a comment

Mac switcher tip – Two for one special

Apple should produce a nice ergonomic keyboard. Since they don’t, I’ve resorted to using a Microsoft wireless natural keyboard and mouse. Microsoft has Mac drivers that add a new control panel to the system preferences, and other than my needing to remember that the Alt key is really my Command key everything is good. Except for the first couple times the Mac went to sleep. With the original Apple keyboard I would press a key or move the mouse to wake from sleep, but this won’t work with the Microsoft keyboard. I needed a workaround.

The first tip is that you can wake a sleeping IR enabled Mac with your Apple Remote Control. If your Mac is sleeping and unresponsive to keyboard and mouse input, this is the thing to try before you resort to power cycling it.

The second tip is to configure your Mac so it gets as close to sleep mode as possible without really sleeping. I have mine set to shut down the monitor after an hour and to idle the hard drives whenever possible, but to never sleep. This is configured in the System Preferences->Energy Saver panel. Since hard drive life is my real concern with the Mac always being on, this configuration lets me get the most important benefits of sleep mode while still responding to the keyboard.

Posted in Apple | Leave a comment