Tech Thought

Tech tips, hints, and general musings. PHP, Perl, Mysql, Javascript, AJAX, JSON, Linux, Mac OSX

Entries for the ‘iPhone Development’ Category

How to Set Title of UITabBarItem Differently to UINavigationController title

A handy code snippet for doing as the title of the post says. Place this in the View Controller: – (void)awakeFromNib { self.navigationItem.title = @”My Long Navigation Item Title”; self.tabBarItem.title = @”Short Title”; [super awakeFromNib]; }

Leave a Comment

How To: iPhone SDK – Play and Record Audio concurrently

Unfortunately, it’s quite a fiddly process to record audio and play it back at the same time on the iPhone.  By default, the sound output is very quiet from the iPhone’s speaker when you are recording sound.  So how do we fix this? First, setup your audio session to record audio: NSURL *url = [NSURL [...]

Comments (8)

How-To: Convert UIImage to Greyscale Equivalent

Here’s a simple code snippet for converting a UIImage to a greyscale equivalent: -(UIImage *) convertToGreyscale:(UIImage *)i { int kRed = 1; int kGreen = 2; int kBlue = 4; int colors = kGreen; int m_width = i.size.width; int m_height = i.size.height; uint32_t *rgbImage = (uint32_t *) malloc(m_width * m_height * sizeof(uint32_t)); CGColorSpaceRef colorSpace = [...]

Leave a Comment

What does iPhone OS 3.0 Mean for your Apps?

Recently I was involved in a podcast regarding the iPhone OS 3.0 upgrade. We looked at all the new features (and some upcoming ones in v3.1) and discussed how they relate to new features clients can develop in their apps. You can hear more here: What does iPhone OS 3.0 Mean for Your Apps (WSP [...]

Leave a Comment

How-To: Convert NSData to NSString

How do you convert an NSData object into it’s string representation?  Should be easy, right?  It is, when you know how… NSString* theString = [[NSString alloc] initWithData:theData encoding:NSASCIIStringEncoding];

Comments (1)

How-To: Detect when MKAnnotation, MKAnnotationView is selected

I’m using MapKit to display a satellite map in one of my apps.  I create custom annotations – and it all works great.  However I wanted to be able to play sounds when a user touches one of my MKAnnotation’s on my MapKit MKMapView so that the sound matches the display of the callout (and [...]

Comments (15)

How-To: Detect if users have turned off the iPhone GPS

Simple and common situation.  You have an app that needs to use the GPS to function correctly.  However, users have the last say in this and can simply say “No” when the iPhone asks them if your application asks to turn on the GPS.  If you don’t deal with this situation, then it’s likely that [...]

Leave a Comment

A solution to: Application failed codesign verification

Okay, so you’ve spent months working hard on your iPhone project, and you finally go gold.  You get sign off from your client, you’ve squashed the last of your bugs and you think “I’m ready to submit this bad boy!”.  You package it up for release as per Apple’s instructions, and then try and upload [...]

Comments (5)

How-To: Remove grey shadow from iPhone UIWebView

By default, when you create a clickable HTML element in a webpage (or in HTML that is displayed in a UIWebView) the iPhone adds a grey shadow/box thing over the top of it when you touch it. Sometimes you don’t want this ‘highlight’ to appear – or you want it to be another color.  Here [...]

Comments (1)

How-To: Solve ‘modifying layer that is being finalized’ iPhone SDK

Okay, so I’ve been getting the ‘modifying layer that is being finalized’ error message when i’m trying to release a subview from a superview: [self.popupPreviewView release]; self.popupPreviewView = nil; The best way to solve this (that I’ve found – please post a comment if you can provide a better one) is to remove the view [...]

Comments (3)

iPhone App Icon Doesn’t appear on iPhone, works in Simulator

If your iPhone App icon isn’t appearing on your phone, but works fine on the simulator, it may be a problem with the way you’ve saved your Icon.png file: I had this problem, until I chose to “show” the extension of the Icon.png file when I saved it from within Preview.  Once I’d done this, [...]

Comments (2)

How-To: Make UIWebView transparent

Common problem, need to apply nice HTML formatting for a section of your page, but want the UIWebView not to appear as a big white box – only the content of the UIWebView to appear. How to do it? myWebView.opaque = NO; myWebView.backgroundColor = [UIColor clearColor]; [myWebView loadHTMLString: @"<html><body style='background-color: transparent'> Content Here</body></html>" baseURL:nil]; The above [...]

Comments (2)

How-To: Jump between tabs using UITabBarController

Sometimes you want to jump between tabs in your iPhone app programatically (ie you don’t want the user to have to touch the tab prior to displaying it). This is very easy to achieve: self.tabBarController.selectedIndex = 3; Where selectedIndex reflects the tab you wish to select (from left to right, starting at 0 for the [...]

Comments (7)

How-To: Change text on Back Button in UINavigationBar (UINavigationController)

If you’re using a UINavigationController to control the navigation in your iPhone app, you’ll find that the “Back” button on your navigation stack can sometimes get very long – particularly if you have long titles for the views you push on to your UINavigationController stack. That’s where changing the text on the ‘Back’ button can [...]

Comments (5)

How-To: Create UIActivityIndicator in iPhone NavigationBar (UINavigationBar)

This is a simple code snippet that can save you hours of mucking around trying to place your activity indicator (spinning icon) in the Navigation Bar of the iPhone.  This example assumes that your view controller has a property of type UIActivityIndicatorView called “self.activityIndicator”: // Create a ‘right hand button’ that is a activity Indicator [...]

Comments (8)

How-To: Show/sync volume control in iPhone SDK

Developing for the iPhone, we wanted to show a volume control that sync’ed with the user’s volume control buttons on the side of the phone.  It turns out, the best way to do this is to show the volume control using the MPVolumeView class (part of the MediaPlayer framework). Here is some example code from [...]

Comments (2)

How-To: Fix ‘Verification Failed’ error (0xe8000001) iPhone Adhoc Distribution

I have had huge problems trying to provide my iPhone Applications to friends using the Adhoc Distribution method.  I thought I was following Apple’s instructions down to the letter: Obtain an Adhoc Distribution Provisioning Profile Install provisioning profile in XCode For my project, create a new build profile called “Adhoc Distribution” copied from the “Release” build [...]

Comments (7)

How-To: Convert a string to NSDate

In Objective-C, you commonly nead to convert a string to an NSDate object.  A simple way to do this is using the NSDateFormatter object.  It provides the dateFromString method which converts a string into an NSDate object.  You do, however, need to tell NSDateFormatter the format the date will be in.  See below example: NSDateFormatter [...]

Comments (4)

UIScrollView not working – scrolling doesn’t work

Okay, so I’ve just spent the last few hours trying to work out why my UIScrollView won’t scroll! The secret, I’ve found, is the following: – (void)viewDidLoad {     [super viewDidLoad];     // Setup scroll view     [scrollView setContentSize:CGSizeMake(backgroundImage.frame.size.width, backgroundImage.frame.size.height+200)]; } You must call setContentSize and pass it an object which has a greater size [...]

Comments (16)

iPhone Development: How to Stream Audio (mp3)

Okay, so we’ve fully taken the plunge and are now developing for the iPhone platform.  Its got a fantastic SDK, with lots of really nice features and tools to help you with your developing fun.  However some tasks are a little more difficult than you’d image. For instance, we wanted to stream an MP3 file [...]

Leave a Comment