iPhone Developer Tips Stats:
|
C Conditional Operator aka Ternary Operator
I’ve always been fond of the conditional operator in C, which is essentially a terse way to write an if/else statement. Given this operator works with three operands, it is often fondly referred to as the ternary operator.
The conditional looks as follow:
condition-test ? first-expression : second-expression
If the condition-test is nonzero, the first-expression is evaluated, otherwise the second-expression is evaluated.
Continue reading this post »
Play iPhone Movies in Portrait Mode with MPMoviePlayerController using Public API’s
It’s been covered by a number of websites and blogs on how to play movies in portrait mode using MPMoviePlayerController. Problem is, every solution that I’ve been able to find uses private API’s to tell the player to flip the direction of play.
Other than the built-in movie player, another option is to use a UIWebview, however, there are a few drawbacks including no support for notifications on when a movie has been preloaded, which is handy for displaying a “please wait” loading message.
This post is introduces another approach to playing a movie in portrait mode without delving into private API’s, and I think you’ll agree, it’s quite clever.
Continue reading this post »
Own an iPhone or iPod touch? I Could Use Your Help To Test a Streaming Video App
Cartoons to Go is a streaming video application that plays vintage cartoons (from 1920’s through 1950’s). Recently there have been a handful of comments about the application not working as expected.
I am looking for 10-15 people who own an iPhone or iPod touch to give the application a try. I’ll create a build specifically for your device or provide a promo code to download the latest version.
What I ask for in return is a thorough run through of the app, testing the streaming speed and performance, as well as exercising the overall UI.
Please send me an email if you are interested to help out jwmuchow at gmail dot com
Accessing iTunes Reports When iTunes is Closed
Over the holiday Apple shutdown iTunes:

Even though you can’t use iTunes to upload new apps, change current app descriptions, prices, etc, you can access your reports with the following link: https://itts.apple.com
NSRange and NSString Objects
When poking around NSString methods you’ll find many references to NSRange, which is nothing more than a C structure that is helpful for describing a series of items, including a starting location and a count. For example, a range is helpful to extract a substring from another string, where you specify the starting location and number of elements needed (examples to follow).
NSRange Definition
NSRange is a structure defined as follows:
typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange;
Cartoons to Go! iPhone Application – Version 1.2
Back in mid-November I posted about a personal iPhone project, Cartoons to Go!. In early December I submitted the 1.1 release which included a major overhaul to the UI going with a retro-TV interface as shown in the figure below:
Compare NSString Objects (Updated)
This tip is for those new to Objective-C and Cocoa and walks through some basics on comparing NSString objects for equality.
Compare NSString objects with ==
NSString *str1 = @"Homebrew"; NSString *str2 = @"Homebrew"; // This compares the addresses of the string if (str1 == str2) NSLog (@"str1 equals str2"); else NSLog (@"str1 does not equal str2");
Show Your Support for iPhoneDeveloperTips.com
Since launching iPhone Developer Tips back in August of 2008, there have been almost 200 tips, tricks and tutorials posted, an average of just over 12 posts per month. The number of page views on a monthly basis is pushing 70,000. All things considered, not too bad…
My primary motivation with this blog is to give back to the same community of developers who have provided help and insight to me over my 20 years in software development. Beyond the obvious time commitment and labor of love to keep writing content, there are costs to keep this machine running – if you would like to show your support for iPhone Developer Tips, please consider clicking through the Amazon link below as you go about your holiday shopping, or if you prefer, a Paypal donation is welcome:
![]()
Thank you very much and Happy Holidays!
John
Get iPhone Device Name, Unique Device Identifier (UDID), OS and Model
The iPhone SDK includes a singleton of class type UIDevice that you can use to retrieve device specific information (this works equally as well with the simulator).
Available Properties in UIDevice
- uniqueIdentifier – identifier guaranteed to be unique for every device
- name – arbitrary name found in General > About setting on device
- systemName – name of the OS running on the device
- systemVersion – current version of the OS
- model- model, such as ”iPhone” or ”iPod touch”
- localizedModel – same as above using a localized string
Tell Xcode Not to Compile a File
By default, when you create a new file or import a file into Xcode, if the file type is recognized as a source file (.c, .m .js, etc), the file is added to the Compile Sources folder in the application target.
You may not always prefer this default action – for example, if a JavaScript file is imported, Xcode does not know what to do with this file type so a compile warning is generated, see the example below:

I ran into this recently when I added a JavaScript file that is associated with an Openx ad that I wanted to displayed inside my application, using a UIWebView.
There is a simple fix, drag/drop the offending file(s) from the Compile Sources folder to the Copy Bundle Resources folder within the applications Target, which will simply include the file in the application bundle with no processing of the file (this is where you will typically see image files, sound files, etc).
In the image below, the file foo.js has been moved into the Copy Bundle Resources folder:

iSimulate Update 1.5
Depending on the type of applications you are building, iSimulate may be just the tool you you need, as it allows testing of functionality on the simulator that is not natively supported through Xcode.
I just got word from vimov, the company behind iSimulate that their latest release 1.5 is now available and includes two key updates:
- All UIKit objects now receive touch events, including scrolling and the keyboard.
- On the iPhone 3GS, events can now be captured by the magnetenometer (compass) and sent to the iPhone Simulator.
If you are not familiar with iSimulate, here is an older post that may be of interest: Introduction to iSimulate. And just for fun, here is a post regarding a giveaway coordinated between iPhone Developer Tips and vimov: iSimulate Giveaway: We Have a Winner.
Gotcha: Case Sensitive PNG Filename
Here’s one that will trip you up if you aren’t careful…look at this code:
timerButton = [[UIButton alloc] initWithFrame:CGRectMake(104, 410, 50, 50)]; // Notice the filename "timer.png" [timerButton setBackgroundImage:[UIImage imageNamed:@"timer.png"] forState:UIControlStateNormal]; [timerButton addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside]; [self.view addSubview:timerButton];
Simple enough, create a button, use the image timer.png for the normal state, and all is well…if you run this code in the simulator. Problem is, if the actual filename of the image is Timer.png the png file will not appear when running this code on device.
If you haven’t run into this while developing an iPhone app, you can’t fully appreciate how time consuming it can be to track this down.
Note: I ran into this while working with Xcode 3.2.1 and building for iPhone OS 3.1.2
Detect Taps on UITabBarController and Determining Class Type
I’ve been working on an application which uses a UITabBarController as the primary means of navigation. One of the tabs leads one to a UIViewController that displays a UIWebview as the main user interface.
The browser based navigation in the webview is based on a legacy (read WAP) website that has a great deal of content, however, it has yet to be updated to take advantage of current browser technology.
The client asked if when a user is on the tab with the browser showing, and would like to return to the home page, rather than navigating with browser-based back buttons, could one tap on the tabbar (again) to reload the main webpage?
Continue reading this post »
Playing Sounds/Audio – AVAudioPlayer
I previously wrote about using Audio Session Services which offers a quick and easy approach for playing short sounds. However, there are a number of limitations, including no control over the volume, playing time is limited to 30 seconds and the only file types supported are AIFF, WAV and CAF.
Sounds with AVAudioPlayer
AVAudioPlayer offers a much wider range of capabilites, including pausing playback, adjusting the volume, tinkering with the playback time (setting and detecting) as well as features for monitoring audio peaks and averages.
The code below shows the basics for setting up a player and playing a sound:
Continue reading this post »
Fade Transition – Fade Images In and Out
Although the iPhone includes a number of effects designed for transitioning between views, sometimes a simple fading effect of one image to another, within the same view, is all you need.
For example, in a recent application during the application startup, I wanted the splash image to fade away, and another image of the primary user interface, to become front and center.
The effect I was after looks similar to the video shown below:
Continue reading this post »









