How to play a sound effect

This is a rather cryptic setup, but here’s how it works: SystemSoundID soundID; NSString *soundFile = [[NSBundle mainBundle]pathForResource:@”yourfile” ofType:@”wav”]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID); AudioServicesPlaySystemSound(soundID); This snippet assumes you’re using a file called yourfile.wav which needs to present in your project. You’ll also need to import the AudioToolbox Framework and import it in your header file.

How to create an Alert View

Here’s how we can create a simple pop-up window via the UIAlertView instance. It can have a title, some info text and several buttons (OK, Cancel, etc). We’ll only deal with one button and not worry about how to read out which button value has been pressed. And here’s how we build this on Objective-C: […]

How to load data in iOS

Here’s how you load data you’ve previously saved with NSUserDefaults. Since you only load data once I’d put this in the AppDelegate.m file (as applicationDidFinishLaunching) or in ViewDidLoad if you have a single view application: // let’s load our data if there is any NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; int theNumber = [defaults integerForKey:@”theNumber”]; NSString […]

How to save data in iOS

There are several ways to save and retrieve data for persistent storage (i.e. when you close your app and open it again). This is the easiest one I can think of: NSUserDefaults. Here’s an example that saves a text field from an IBOutlet. We’re saving both a string and an integer. We can use this […]

How to rename your iOS App in Xcode 4.x.x

Find the info.plist file (in the Supporting Files folder). Say your app is called MyApp, then you’re looking for a file called MyApp-info.plist Say hello to a scary list of key/value pairs In here, find the Bundle Display Name Change it from the default ${PRODUCT_NAME} to your title Build and see your title underneath your […]

How to add a Framework to Xcode 4.x.x

First head over to the top left corner of Xcode. Click on the Project Navigator to show all your files. Next click the big blue A icon right at the top of that list. Just right of it you see two headings: Project and Targets. Click on your app name under Targets. If this pane […]

How to send an email in iOS

This is tricky but doable. We’re using the MFMailComposeViewController protocol for this (don’t ask). This will open the mail app on your device. Older devices without mail sending capability will crash when you call this method so we’ll check before we do this. if ([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; mailer.mailComposeDelegate = […]