Jul 15, 2010
I previously explained how to use NSUserDefaults to your advantage, basically being the OSX equivalent to the Windows registry. User Defaults are the way how you can persist small amounts of data in a convenient way. They are basically dictionaries that the system takes care of for you with the added benefit of being cached in memory.
Today we’ll up it one notch. Session 124 of the WWDC 2010 videos brought to my attention the fact that there’s also a mechanism to provide default values for the defaults. Up until now I would have retrieved an object from the defaults, checked if it’s nil and then set the value. Consider the following code snipped from SpeakerClock:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSNumber *countdownNum = [defaults objectForKey:@"Countdown"];
countdown = [countdownNum doubleValue];
countdown = self.currentPreset.startDuration;
This works, but it’s not elegant. Wouldn’t it be great if we could pre-register those values so that a simple retrieval always has a result?
Jul 10, 2010
The iPhone 4 rulez, bar none.
Podcast: Download (19.1MB)
Show notes, aka “my script” after the break.
Jul 10, 2010
Yesterday I found an e-mail in my inbox that gave me a bit of a spooky feeling in my stomach. Ordinarily such a mail would have quickly ended up in my trash if it weren’t for the details they put in there.
Why would Microsoft be contacting me? They obviously did a bit of digging or reading to know that I created the apps for CCS Publishing. They didn’t bother to check on my references page though. The ACLS app was done by somebody else. But still it shows a fair amount of data mining as they appear to have checked those apps’ rankings and then cross referenced them with who was the real author.
Jul 04, 2010
UPDATE: Added handleOpenURL to the flow charts. Added UIApplicationExitsOnSuspend. Untangled some lines.
UPDATE: renamed deprecated handleOpenURL to newer name.
Now that we all are moving our source code gradually to iOS 4 I had to pause and think a bit about where to move which code. A problem that I’m facing frequently when updating a project is that the didFinishLaunching is only called if the app really launches.
That poses a bit of a challenge if you are used to doing things like refreshing images or other files off the internet. An app that is resumed from standby does no longer go through this delegate method. So an app that would always show fresh content upon launch before 4.0 multitasking would no longer load any new content as soon as you build it for 4.0. That’s actually one of the main reasons why I have not yet had time to update MyAppSales to 4.0.
To gain the possibility for “fast app switching” you actually don’t need to do anything. All apps automatically support it because they no longer get terminated if the user pushes the Home button. They get put into a sleep mode while the iPhone still has enough memory for everything else. It’s only if RAM runs out that the OS starts killing apps. There is begins with the ones that have the most memory reserved.
I grabbed the free trial of Omnigraffle and the Non-techie Process Flowchart Stencils by gfraser. Then I researched when all these various delegate methods of UIApplication are being called and drew charts to illustrate the flow.
By inhaling first how it was before multitasking and then upgrading your mental process to backgrounding we can begin to fully appreciate how it all fits together.
Jul 04, 2010
Prior to iOS 3.2 your only option for playing videos on iPhone was to use MPMoviePlayerController and only in full screen mode. It made sense because who really wants to look at stamp sized videos on his mobile phone.
The iPad changed all that and brought along several changes in how you can place videos. All those changes also made it into the iPhone SDKs. Here’s a pitfall that you might not have seen if you didn’t upgrade the SDK on one of your iPhone projects.
Jul 01, 2010
Thanks for your article on UIImage from UIView.
Need one more favor; I am in situation where I want to draw line or area (e.g. rectangle) on UI Image (e.g. Blue print) and save it again.
Basically I will show image and put circle / rectangle on image showing area in blue print and save it.
How should I do that? Can you please suggest approach, sample codes etc?
So the task is to take a UIImage, make it writable in some way and then make a new image out of that for later use. Off the top of my head, I can immediately think of two ways to do that: with UIKit and with CoreGraphics. CoreGraphics has a slight advantage, being lower level, of being thread-safe. But for a simple graphical addition to an existing image I see nothing wrong with UIKit. As usual you should only do very quick operations with UIKit because it requires to be run on the main thread which is the only thread updating the user interface.
Jun 29, 2010
It’s one of these days there the arrival of a new and shiny Apple toy is diminishing productivity to zero. My iPhone 4 arrived at lunchtime and so I spent my afternoon unboxing and setting up my new iDevice.
I had purchased a black 32 GB iPhone 4 on Apple’s UK store. The kingdom is a tier 1 country which got it at the same time as the US. What’s also great is that the empire’s Apple online store sells the variant without SIM-lock. A necessity if you want to be able to use the iPhone 4 as a phone in your home cellular network. Since I ordered Apple added this paragraph to clarify this:
When you purchase your iPhone from the Apple Online Store, you’ll get it SIM-free. So you can sign up for service with the carrier of your choice and change your carrier at any time
My friend Michael Kaye in London purchased the phone for me (32 GB for 599 GBP) and shipped it via parcel service to Austria. This cost me another 60 pounds, but I had insurance and tracking. The latter was kind of weird, because the original carrier Parcelforce handed off the package to FedEx and so I got incomplete and somewhat strange tracking info. But fortunately it turned out fine.
I’m unboxing the iPhone after the back, check out my YouTube video!
Jun 26, 2010
As of SDK 3.2 most of the touch handling code in stock controls has been taken out and replaced with this amazing new technology called Gesture Recognizers. This means besides of using them yourself and creating your own you can also fiddle with behaviors of standard controls if they interfere with your own gestures.
I’m currently working quite a bit on something based on UIScrollView and there I found several things that I needed to tweak.
The first modification I did was to get around a bug in UIScrollView. I did not actually want user zooming in my scroll view, but just use the setting of the zoomLevel to scale images without having to redraw them. And you can only set the zoomLevel to values between min and max.
So, during autorotation, I reduced the min zoom scale, set the new zoom level and then set min and max both to the new zoom. But the problem with this, as of SDK 3.2., is that if you change the min or max zoomLevel property the scroll silently adds a UIPinchGestureRecognizer to itself via the addGestureRecognizer method that now all views have.
Jun 22, 2010
A not-to-be-named friend asked me:
I would like your opinion the GM build. Should I (not sure how) remove it and then load the new iOS 4.0? I know it wouldn’t have the game center, but I don’t use that anyway. I am afraid if I don’t remove, the software will expire (happened on beta 4 and then I couldn’t use the phone (or back up first) until I could load the latest.
If you’re one of those developers that managed to install the iOS 4.0 Gold Master right after Uncle Steve announced it, then you might wonder if you should update to the really final release that came out just now.
Wait! That’s a trick question…!