Zach Smith
Zach Smith

Reputation: 5674

Trying to add a Vibrate and Sound to my Alert View

One thing I've learned at engineering school is to always to intense validation of input. I think it's great that with the iPhone SDK you can create a sound and a vibrate option. I would like to put both of these into my Alert View, which shows when the user doesn't fill in a field correctly.

However, I'm getting a ton of errors. Is it not possible to put the vibrate and sound options within an alert view? Here is the code I am using below,

       //create vibrate 
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

        //play sound
    SystemSoundID pmph;
    id sndpath = [[NSBundle mainBundle] 
                  pathForResource:@"mySound" 
                  ofType:@"wav" 
                  inDirectory:@"/"];
    CFURLRef baseURL = (CFURLRef) [[NSURL alloc] initFileURLWithPath:sndpath];
    AudioServicesCreateSystemSoundID (baseURL, &pmph);
    AudioServicesPlaySystemSound(pmph); 
    [baseURL release];

        //show alert view
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Age Error"
                          message:@"Your age must be at least 40 years old and less than 100 years old"
                          delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [alert show];
    [alert release];

I have all of the above code in the

- (void)textFieldDidEndEditing:(UITextField *)textField

method.

Here is the errors I get when I try to run it http://screencast.com/t/Nzc5NDdhMmI

Any help would be greatly appreciated. Not sure what I'm doing wrong since I'm pasting this code directly from another source online.

Upvotes: 1

Views: 1038

Answers (1)

kubi
kubi

Reputation: 49354

I've never used the Sound Services, but it looks like you need to import the AudioToolbox framework.

#import <AudioToolbox/AudioToolbox.h>

Upvotes: 4

Related Questions